Dwelle Dwelle - 1 year ago 72
Git Question

How to review merge commits to detect incorrect hunks

Normally when reviewing merge commits, we do

git diff-tree --cc <commit>
(or simply
git show <commit>
), but I'm faced with the following problem:

Say you merge
and during conflict resolution you need to choose a hunk from either
branch to resolve it. Let's say that the hunk in
supersedes the hunk in
for some reason, but since you might not know about it and judging simply by e.g. commit date, you choose hunk from

If you make no other modifications than that, the multi-parent diff via
git show
won't show any diff output, because the resulting hunk is in its entirety in one of the parent commits.

To further elaborate, if you have this conflict:

<<<<<<< HEAD
>>>>>>> b

And remove either
hunk and choose
, or vice versa, the
git show <merge_commit>
won't show anything at all, thus preventing you to see what hunk was chosen during the merge.

This can potentially result in a regression hard to find down the line.

How could I see what hunks were chosen during a conflict resolution?

Edit: what I'm after is to view just the hunks that were conflicted (thus not auto-merged).

Answer Source

Edit: what I'm after is to view just the hunks that were conflicted (thus not auto-merged).

Not the answer you were looking for: this is not possible with git commands. git does not keep track of how a merge was resolved in any way or fashion. You would need something like a "4-way diff" (A, B, common parent and merge result), which I never heard of.

In theory, you could go back and write yourself a program that re-does the original 3-way merge to produce the intermediate file (with the conflict markers) and diff that to the merge result. git has no provisions to do that for you though.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download