git-diff: fix missing --merge-base docs

When `git diff --merge-base` was introduced at around Git 2.30, the documentation included a few errors. In the example given for `git diff --cached --merge-base`, the `--cached` flag was omitted for the `--merge-base` example. Add the missing flag. In the `git diff <commit>` case, we failed to mention that `--merge-base` is an available option. Give the usage of `--merge-base` as an option there. Finally, there are two errors in the usage of `git diff`. Firstly, we do not mention `--merge-base` in the `git diff --cached` case. Mention it so that it's consistent with the documentation. Secondly, we put the `[--merge-base]` in between `<commit>` and `[<commit>...]`. Move the `[--merge-base]` so that it's beside `[<options>]` which is a more logical grouping. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Jul 10, 2021 at 02:28 UTC eb448631fb541239d91709d812b92bf2b57bc733
2 files changed +9 -5
Documentation/git-diff.txt
+7 -3
@@ -51,16 +51,20 @@ files on disk.
51 --staged is a synonym of --cached.
52 +
53 If --merge-base is given, instead of using <commit>, use the merge base
54 -of <commit> and HEAD. `git diff --merge-base A` is equivalent to
55 -`git diff $(git merge-base A HEAD)`.
54 +of <commit> and HEAD. `git diff --cached --merge-base A` is equivalent to
55 +`git diff --cached $(git merge-base A HEAD)`.
56
57 -'git diff' [<options>] <commit> [--] [<path>...]::
57 +'git diff' [<options>] [--merge-base] <commit> [--] [<path>...]::
58
59 This form is to view the changes you have in your
60 working tree relative to the named <commit>. You can
61 use HEAD to compare it with the latest commit, or a
62 branch name to compare with the tip of a different
63 branch.
64 ++
65 +If --merge-base is given, instead of using <commit>, use the merge base
66 +of <commit> and HEAD. `git diff --merge-base A` is equivalent to
67 +`git diff $(git merge-base A HEAD)`.
68
69 'git diff' [<options>] [--merge-base] <commit> <commit> [--] [<path>...]::
70
builtin/diff.c
+2 -2
@@ -25,8 +25,8 @@
25
26 static const char builtin_diff_usage[] =
27 "git diff [<options>] [<commit>] [--] [<path>...]\n"
28 -" or: git diff [<options>] --cached [<commit>] [--] [<path>...]\n"
29 -" or: git diff [<options>] <commit> [--merge-base] [<commit>...] <commit> [--] [<path>...]\n"
28 +" or: git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]\n"
29 +" or: git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]\n"
30 " or: git diff [<options>] <commit>...<commit>] [--] [<path>...]\n"
31 " or: git diff [<options>] <blob> <blob>]\n"
32 " or: git diff [<options>] --no-index [--] <path> <path>]\n"