diff --git a/Documentation/git.txt b/Documentation/git.txt index 13f83a2a3a..302607a496 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -9,7 +9,7 @@ git - the stupid content tracker SYNOPSIS -------- [verse] -'git' [--version] [--help] [-C ] [-c =] +'git' [-v | --version] [-h | --help] [-C ] [-c =] [--exec-path[=]] [--html-path] [--man-path] [--info-path] [-p|--paginate|-P|--no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=] @@ -39,6 +39,7 @@ or https://git-scm.com/docs. OPTIONS ------- +-v:: --version:: Prints the Git suite version that the 'git' program came from. + @@ -46,6 +47,7 @@ This option is internally converted to `git version ...` and accepts the same options as the linkgit:git-version[1] command. If `--help` is also given, it takes precedence over `--version`. +-h:: --help:: Prints the synopsis and a list of the most commonly used commands. If the option `--all` or `-a` is given then all diff --git a/git.c b/git.c index 3d8e48cf55..5ff4f3e25b 100644 --- a/git.c +++ b/git.c @@ -25,7 +25,7 @@ struct cmd_struct { }; const char git_usage_string[] = - N_("git [--version] [--help] [-C ] [-c =]\n" + N_("git [-v | --version] [-h | --help] [-C ] [-c =]\n" " [--exec-path[=]] [--html-path] [--man-path] [--info-path]\n" " [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]\n" " [--git-dir=] [--work-tree=] [--namespace=]\n" @@ -146,7 +146,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) * commands can be written with "--" prepended * to make them look like flags. */ - if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version")) + if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h") || + !strcmp(cmd, "--version") || !strcmp(cmd, "-v")) break; /* @@ -893,8 +894,10 @@ int cmd_main(int argc, const char **argv) argc--; handle_options(&argv, &argc, NULL); if (argc > 0) { - /* translate --help and --version into commands */ - skip_prefix(argv[0], "--", &argv[0]); + if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0])) + argv[0] = "version"; + else if (!strcmp("--help", argv[0]) || !strcmp("-h", argv[0])) + argv[0] = "help"; } else { /* The user didn't specify a command; give them help */ commit_pager_choice(); diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 6c3e1f7159..6c33a43690 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -181,7 +181,7 @@ for cmd in git "git help" do test_expect_success "'$cmd' section spacing" ' test_section_spacing_trailer git help <<-\EOF && - usage: git [--version] [--help] [-C ] [-c =] + usage: git [-v | --version] [-h | --help] [-C ] [-c =] These are common Git commands used in various situations: