git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/4] builtin/diff: learn --merge-base

From
Denton Liu <liu.denton@gmail.com>
Date
Sep 10, 2020, 07:32 UTC
Message-ID
<cover.1599723087.git.liu.denton@gmail.com>
In-Reply-To
<cover.1599332861.git.liu.denton@gmail.com>

The range-notation in `git diff` has been cited as a mistake since diff compares two endpoints, not whole ranges.[0] In fact, the ranges seem to take on the opposite meanings when compared to range notation in `git log`.

In an effort to reduce the use of range notation as much as possible, introduce the `--merge-base` flag, slightly modified from a suggestion by Jonathan Nieder.[1] This flag allows us to replace the first commit given on the command-line with its merge base between the first and second commits. This allows us to gently deprecate the `...` form entirely, although that is left as an exercise to the reader ;)

One additional bonus is that this flag allows the "after" side to be not just constrained to a commit (like with `...` notation). It can now be the working tree or the index as well.

The `--merge-base` name isn't very satisfying. If anyone has any better suggestions, please let me know.

Changes since v1:
* Implement Junio's documentation suggestions
* Update git diff's usage to include this option

[0]: https://lore.kernel.org/git/xmqqy2v26hu0.fsf@gitster-ct.c.googlers.com/ [1]: https://lore.kernel.org/git/20191223215928.GB38316@google.com/

Denton Liu (4):
  t4068: remove unnecessary >tmp
  git-diff.txt: backtick quote command text
  builtin/diff: parse --no-index using parse_options()
  builtin/diff: learn --merge-base
 Documentation/git-diff.txt | 40 +++++++++++-----
 builtin/diff.c             | 94 +++++++++++++++++++++++++++++++++-----
 diff-no-index.c            | 15 ++----
 t/t4068-diff-symmetric.sh  | 89 ++++++++++++++++++++++++++++++++++--
 4 files changed, 198 insertions(+), 40 deletions(-)
Range-diff against v1:
1:  231ba3f661 ! 1:  4f219cf0d1 builtin/diff: learn --merge-base
    @@ Commit message
     
         Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
     
    +
    + ## Notes ##
    +    The `--merge-base` name isn't very satisfying. If anyone has any
    +    suggestions for alternative names, please let me know.
    +
      ## Documentation/git-diff.txt ##
     @@ Documentation/git-diff.txt: SYNOPSIS
      'git diff' [<options>] [<commit>] [--] [<path>...]
    @@ Documentation/git-diff.txt: files on disk.
     +equivalent to `git diff $(git merge-base A B) B`.
     ++
     +In the case where one commit is given, a diff is displayed between the
    -+merge base and the working tree or the index if `--cached` is given.
    -+`git diff --merge-base A` is equivalent to `git diff $(git merge-base A
    -+HEAD)`.
    ++merge base of the commit and the HEAD and the working tree or the index
    ++if `--cached` is given. `git diff --merge-base A` is equivalent to `git
    ++diff $(git merge-base A HEAD)`.
     ++
     +In the case where no commits are given, this form behaves identically to
     +as if no `--merge-base` were supplied.
    @@ builtin/diff.c
      
      #define DIFF_NO_INDEX_EXPLICIT 1
      #define DIFF_NO_INDEX_IMPLICIT 2
    +@@ builtin/diff.c: static const char builtin_diff_usage[] =
    + "git diff [<options>] [<commit>] [--] [<path>...]\n"
    + "   or: git diff [<options>] --cached [<commit>] [--] [<path>...]\n"
    + "   or: git diff [<options>] <commit> [<commit>...] <commit> [--] [<path>...]\n"
    +-"   or: git diff [<options>] <commit>...<commit>] [--] [<path>...]\n"
    ++"   or: git diff [<options>] --merge-base [<commit> [<commit>]] [--] [<path>...]\n"
    + "   or: git diff [<options>] <blob> <blob>]\n"
    + "   or: git diff [<options>] --no-index [--] <path> <path>]\n"
    + COMMON_DIFF_OPTIONS_HELP;
     @@ builtin/diff.c: int cmd_diff(int argc, const char **argv, const char *prefix)
      	int blobs = 0, paths = 0;
      	struct object_array_entry *blob[2];
    @@ builtin/diff.c: int cmd_diff(int argc, const char **argv, const char *prefix)
      			   DIFF_NO_INDEX_EXPLICIT,
      			   PARSE_OPT_NONEG),
     +		OPT_BOOL(0, "merge-base", &merge_base,
    -+			 N_("use the merge base between the two commits as the diff base")),
    ++			 N_("compare with the merge base between two commits")),
      		OPT_END(),
      	};
      
-- 
2.28.0.618.gf4bc123cb7
Previous: Junio C HamanoNext: Denton Liu
Message 7 of 58 in “builtin/diff: learn --merge-base”
  1. 0/4 builtin/diff: learn --merge-baseDenton Liu, Sep 5, 2020
  2. 1/4 t4068: remove unnecessary >tmpDenton Liu, Sep 5, 2020
  3. 3/4 builtin/diff: parse --no-index using parse_options()Denton Liu, Sep 5, 2020
  4. 2/4 git-diff.txt: backtick quote command textDenton Liu, Sep 5, 2020
  5. 4/4 builtin/diff: learn --merge-baseDenton Liu, Sep 5, 2020
  6. Junio C HamanoSep 6, 2020
  7. 0/4 builtin/diff: learn --merge-baseDenton Liu, Sep 10, 2020
  8. 1/4 t4068: remove unnecessary >tmpDenton Liu, Sep 10, 2020
  9. 2/4 git-diff.txt: backtick quote command textDenton Liu, Sep 10, 2020
  10. 3/4 builtin/diff: parse --no-index using parse_options()Denton Liu, Sep 10, 2020
  11. Junio C HamanoSep 10, 2020
  12. Denton LiuSep 13, 2020
  13. Junio C HamanoSep 13, 2020
  14. 4/4 builtin/diff: learn --merge-baseDenton Liu, Sep 10, 2020
  15. 00/10 builtin/diff: learn --merge-baseDenton Liu, Sep 17, 2020
  16. 01/10 t4068: remove unnecessary >tmpDenton Liu, Sep 17, 2020
  17. 02/10 git-diff-index.txt: make --cached description a proper sentenceDenton Liu, Sep 17, 2020
  18. 10/10 contrib/completion: complete `git diff --merge-base`Denton Liu, Sep 17, 2020
  19. 09/10 builtin/diff-tree: learn --merge-baseDenton Liu, Sep 17, 2020
  20. Junio C HamanoSep 17, 2020
  21. Denton LiuSep 18, 2020
  22. Junio C HamanoSep 18, 2020
  23. Denton LiuSep 20, 2020
  24. Junio C HamanoSep 21, 2020
  25. Denton LiuSep 21, 2020
  26. Junio C HamanoSep 21, 2020
  27. Junio C HamanoSep 21, 2020
  28. Denton LiuSep 21, 2020
  29. Junio C HamanoSep 21, 2020
  30. Denton LiuSep 23, 2020
  31. Junio C HamanoSep 25, 2020
  32. Denton LiuSep 26, 2020
  33. 08/10 builtin/diff-index: learn --merge-baseDenton Liu, Sep 17, 2020
  34. Junio C HamanoSep 17, 2020
  35. Jeff KingSep 17, 2020
  36. Junio C HamanoSep 18, 2020
  37. Jeff KingSep 18, 2020
  38. 05/10 diff-lib: accept option flags in run_diff_index()Denton Liu, Sep 17, 2020
  39. Junio C HamanoSep 17, 2020
  40. 04/10 contrib/completion: extract common diff/difftool optionsDenton Liu, Sep 17, 2020
  41. 06/10 diff-lib: define diff_get_merge_base()Denton Liu, Sep 17, 2020
  42. Junio C HamanoSep 17, 2020
  43. Denton LiuSep 18, 2020
  44. Junio C HamanoSep 19, 2020
  45. 03/10 git-diff.txt: backtick quote command textDenton Liu, Sep 17, 2020
  46. 07/10 t4068: add --merge-base testsDenton Liu, Sep 17, 2020
  47. 00/10 builtin/diff: learn --merge-baseDenton Liu, Sep 20, 2020
  48. 01/10 t4068: remove unnecessary >tmpDenton Liu, Sep 20, 2020
  49. 02/10 git-diff-index.txt: make --cached description a proper sentenceDenton Liu, Sep 20, 2020
  50. 06/10 diff-lib: define diff_get_merge_base()Denton Liu, Sep 20, 2020
  51. 05/10 diff-lib: accept option flags in run_diff_index()Denton Liu, Sep 20, 2020
  52. 03/10 git-diff.txt: backtick quote command textDenton Liu, Sep 20, 2020
  53. 07/10 t4068: add --merge-base testsDenton Liu, Sep 20, 2020
  54. 08/10 builtin/diff-index: learn --merge-baseDenton Liu, Sep 20, 2020
  55. Martin ÅgrenSep 29, 2020
  56. 04/10 contrib/completion: extract common diff/difftool optionsDenton Liu, Sep 20, 2020
  57. 09/10 builtin/diff-tree: learn --merge-baseDenton Liu, Sep 20, 2020
  58. 10/10 contrib/completion: complete `git diff --merge-base`Denton Liu, Sep 20, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.