git show of a merge commit

前端 未结 2 1167
小鲜肉
小鲜肉 2020-11-29 20:02

when I have a merge commit and run git show #commit, it shows only commit log, not the the diff to the real change, like

commit c0f50178901e09a1237f7b9d9173         


        
2条回答
  •  情深已故
    2020-11-29 20:13

    As mentioned here, those solution involve showing a combined diff, like:

    git diff --cc $M $M^1 $M^2 $(git merge-base $M^1 $M^2)
    

    But: the output from "diff --cc" did not show the original paths when the merge involved renames.
    A new option in Git 2.22 (Q1 2019) adds the paths in the original trees to the output.

    git diff --cc --combined-all-paths $M $M^1 $M^2 $(git merge-base $M^1 $M^2)
    

    log,diff-tree: add --combined-all-paths option

    The combined diff format for merges will only list one filename, even if rename or copy detection is active.

    For example, with raw format one might see:

    ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM describe.c
    ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM   bar.sh
    ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR   phooey.c
    

    This doesn't let us know what the original name of bar.sh was in the first parent, and doesn't let us know what either of the original names of phooey.c were in either of the parents.

    In contrast, for non-merge commits, raw format does provide original filenames (and a rename score to boot).
    In order to also provide original filenames for merge commits, add a --combined-all-paths option (which must be used with either -c or --cc, and is likely only useful with rename or copy detection active) so that we can print tab-separated filenames when renames are involved.

    This transforms the above output to:

    ::100644 100644 100644 fabadb8 cc95eb0 4866510 MM desc.c  desc.c  desc.c
    ::100755 100755 100755 52b7a2d 6d1ac04 d2ac7d7 RM   foo.sh  bar.sh  bar.sh
    ::100644 100644 100644 e07d6c5 9042e82 ee91881 RR   fooey.c fuey.c  phooey.c
    

    Further, in patch format, this changes the from/to headers so that instead of just having one "from" header, we get one for each parent.
    For example, instead of having

    --- a/phooey.c
    +++ b/phooey.c
    

    we would see

    --- a/fooey.c
    --- a/fuey.c
    +++ b/phooey.c
    

提交回复
热议问题