Dwelle Dwelle - 3 months ago 12
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
B
into
A
and during conflict resolution you need to choose a hunk from either
A
or
B
branch to resolve it. Let's say that the hunk in
A
supersedes the hunk in
B
for some reason, but since you might not know about it and judging simply by e.g. commit date, you choose hunk from
B
branch.

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
aaa
=======
bbb
>>>>>>> b


And remove either
aaa
hunk and choose
bbb
, 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

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.