how to get git log -p to show changes in merge commits

后端 未结 2 1719
栀梦
栀梦 2021-02-08 14:24

I have a branch with a function definition missing but the function is still being used causing a crash. The function definition must have been deleted during a merge. I have do

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-08 15:16

    This leads me to believe that 'git log -p' doesn't show merge changes?

    It does, with Git 2.31 (Q1 2021): "git log"(man) learned a new --diff-merges= option.

    See commit af04d8f, commit 1d24509, commit e58142a, commit 8efd2ef, commit b5ffa9e, commit 388091f, commit 5071c75, commit a6d19ec, commit 5733b20, commit 8c0ba52, commit 255a4da, commit 3d2b5f2, commit a6e66af, commit d9b1bc6, commit 1a2c4d8, commit 6fc944d, commit ec315c6, commit 14c14b4, commit e121b4b, commit 0c627f5, commit 3291eea, commit 3b6c17b, commit 09322b1, commit 564a4fc, commit 4f54544, commit 7acf0d0, commit 18f0947, commit a37eec6, commit 3d4fd94, commit 027c478, commit 299a663, commit 891e417 (21 Dec 2020) by Sergey Organov (sorganov).
    (Merged by Junio C Hamano -- gitster -- in commit aac006a, 05 Feb 2021)

    diff-merges: implement new values for --diff-merges

    Signed-off-by: Sergey Organov

    We first implement new options as exact synonyms for their original counterparts, to get all the infrastructure right, and keep functional improvements for later commits.

    The following values are implemented:

    --diff-merges=            old equivalent 
    first|first-parent      = --first-parent (only format implications)
    sep|separate            = -m
    comb|combined           = -c
    dense| dense-combined   = `--cc`
    

    diff-merges: add old mnemonic counterparts to --diff-merges

    Signed-off-by: Sergey Organov

    This adds --diff-merges={m|c|cc} values that match mnemonics of old options, for those who are used to them.

    Note that, say, --diff-meres=cc behaves differently than --cc, as the latter implies -p and therefore enables diffs for all the commits, while the former enables output of diffs for merge commits only.

    diff-merges: add '--diff-merges=1' as synonym for 'first-parent'

    Signed-off-by: Sergey Organov

    As we now have --diff-merges={m|c|cc}, add --diff-merges=1 as synonym for --diff-merges=first-parent, to have shorter mnemonics for it as well.

    doc/git-show: include --diff-merges description

    Signed-off-by: Sergey Organov

    Move description of --diff-merges option from git-log.txt to diff-options.txt so that it is included in the git-show(man) help.

    diff-options now includes in its man page:

    ifdef::git-log[]

    --diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)

    --no-diff-merges

    Specify diff format to be used for merge commits. Default is {diff-merges-default} unless --first-parent is in use, in which case first-parent is the default.

    --diff-merges=(off|none):

    --no-diff-merges:

    Disable output of diffs for merge commits. Useful to override implied value.

    --diff-merges=first-parent:

    --diff-merges=1:

    This option makes merge commits show the full diff with respect to the first parent only.

    --diff-merges=separate:

    --diff-merges=m:

    -m:

    This makes merge commits show the full diff with respect to each of the parents.
    Separate log entry and diff is generated for each parent.
    -m doesn't produce any output without -p.

    --diff-merges=combined:

    --diff-merges=c:

    -c:

    With this option, diff output for a merge commit shows the differences from each of the parents to the merge result simultaneously instead of showing pairwise diff between a parent and the result one at a time.

    Furthermore, it lists only files which were modified from all parents.

    -c implies -p.

    --diff-merges=dense-combined:

    --diff-merges=cc:

    --cc:

    With this option the output produced by --diff-merges=combined is further compressed by omitting uninteresting hunks whose contents in the parents have only two variants and the merge result picks one of them without modification. --cc implies -p.

    --combined-all-paths

    This flag causes combined diffs (used for merge commits) to list the name of the file from all parents. It thus only has effect when --diff-merges=[dense-]combined is in use, and is likely only useful if filename changes are detected (i.e. when either rename or copy detection have been requested). endif::git-log[]

    git log now includes in its man page:

    :diff-merges-default: off

    git show now includes in its man page:

    DIFF FORMATTING

    The options below can be used to change the way git show generates diff output.

    git show now includes in its man page:

    :diff-merges-default: dense-combined


    This is based on the work from Git 2.29 (Q4 2020), formally documented:

    See commit 5fbb4bc, commit 9a6d515, commit 6cea104, commit 6f2e02a, commit 9ab89a2, commit 6fae74b, commit eed5332 (29 Jul 2020) by Jeff King (peff).
    (Merged by Junio C Hamano -- gitster -- in commit eca8c62, 17 Aug 2020)

    doc/git-log: clarify handling of merge commit diffs

    Signed-off-by: Jeff King

    It can be surprising that git-log doesn't show any diff for merge commits by default.
    Arguably "--cc" would be a reasonable default, but it's very expensive (which is why we turn it on for "git show"(man) but not for "git log").

    Let's at least document the current behavior, including the recent "--first-parent implies -m" case

    git log now includes in its man page:

    Note that unless one of -c, --cc, or -m is given, merge commits will never show a diff, even if a diff format like --patch is selected, nor will they match search options like -S.

    The exception is when --first-parent is in use, in which merges are treated like normal single-parent commits (this can be overridden by providing a combined-diff option or with --no-diff-merges).


    And you also have:

    To countermand the implicit "-m" option when the "--first-parent" option is used with "git log"(man) , we added the "--[no-]diff-merges" option in the jk/log-fp-implies-m topic.

    To leave the door open to allow the "--diff-merges" option to take values that instructs how patches for merge commits should be computed (e.g. "cc"? "-p against first parent?"), redefine "--diff-merges" to take non-optional value, and implement "off" that means the same thing as "--no-diff-merges".

    See commit 298889d, commit 405a2fd, commit 6501580 (06 Aug 2020) by Sergey Organov (sorganov).
    (Merged by Junio C Hamano -- gitster -- in commit a555b51, 17 Aug 2020)

    doc/git-log: describe --diff-merges=off

    Signed-off-by: Sergey Organov

    git log now includes in its man page:

    --diff-merges=off

    --no-diff-merges

    Disable output of diffs for merge commits (default).
    Useful to override -m, -c, or --cc.

提交回复
热议问题