'git help' shows common commands in alphabetical order:
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
[...]
without any indication of how commands relate to high-level
concepts or each other. Revise the output to group commands by
concept, like this:
The most commonly used git commands are:
* starting a working area:
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
* working on the current change:
add Add file contents to the index
reset Reset current HEAD to the specified state
[...]
Helped-by: Junio C Hamano [off-list ref]
Helped-by: Eric Sunshine [off-list ref]
Signed-off-by: Sébastien Guimmara <redacted>
---
help.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/help.c b/help.c
index 2072a87..c8b0bb6 100644
--- a/help.c
+++ b/help.c
@@ -218,18 +218,44 @@ void list_commands(unsigned int colopts,
}
}
+int cmd_group_cmp(const void *elem1, const void *elem2)
+{
+ int group1, group2;
+
+ group1 = ((struct cmdname_help *) elem1)->group;
+ group2 = ((struct cmdname_help *) elem2)->group;
+
+ if (group1 == group2)
+ return 0;
+ if (group1 > group2)
+ return 1;
+ else
+ return -1;
+}
+
void list_common_cmds_help(void)
{
int i, longest = 0;
+ unsigned char current_grp = -1;
for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
if (longest < strlen(common_cmds[i].name))
longest = strlen(common_cmds[i].name);
}
+ qsort(common_cmds, ARRAY_SIZE(common_cmds),
+ sizeof(common_cmds[0]), cmd_group_cmp);
+
puts(_("The most commonly used git commands are:"));
+
for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
- printf(" %s ", common_cmds[i].name);
+ if (common_cmds[i].group != current_grp) {
+ printf("\n * %s:\n", _(common_cmd_groups[common_cmds[i].group]));
+ }
+
+ current_grp = common_cmds[i].group;
+
+ printf(" %s ", common_cmds[i].name);
mput_char(' ', longest - strlen(common_cmds[i].name));
puts(_(common_cmds[i].help));
}--
2.4.0