4

Consider the following git log with the following commits

6752364 *   Merge branch 'java-branch'
        |\  
b9e9e66 | * Add an unrelated file
14a7cb9 | * Change favorite language to Java
7b07a43 * | Change favorite language to C#
        |/  
8788146 * C++ is my favorite programming language

You can clone the repo, I made as example for this question.

My goal is to inspect what merge conflict resolution was made in the merge commit 6752364. For instance, I did this merge so I know that I was prompted for conflict resolution on the readme.md file which I did using Meld. I selected "Java" version over "C#" version. I can't see this decision recorded anywhere in the merge commit (not in a way a can easily check at least, more on this later). All I can check is the final state of the file.

There are multiple answers in StackOverflow regarding this problem that simply say that I should use git show to inspect what kind of resolution was performed. However my git show provides me with this output:

commit 6752364571d0e9c89ddbb3bd287af2e26eb23e59 (HEAD -> master, origin/master)
Merge: 7b07a43 b9e9e66
Author: Henrique Jung <henriquenj@gmail.com>
Date:   Sun Oct 4 21:18:54 2020 +0200

    Merge branch 'java-branch'

I speculate that git show is only useful if I had solved the conflict using neither parent commit, but rather a third version not available on any of them (like writing "Haskell" on Meld). How can I inspect a merge commit where the conflict resolution is done using one of the versions "cleanly" i.e. picking parent A or parent B directly? Where is my preference for "Java" over "C#" recorded?

My git version is 2.25.1.


Maybe you are thinking: well I can just look at the commit on GitHub or maybe gitg which shows me the diff. But there's a catch: it shows the whole diff. It shows an unrelated file that was never part of the conflict resolution in the first place. So I could inspect the resolution this way, but for big merges it would add a lot of noise, I would be reviewing both branches again.

This question arose when I was reviewing a big merge with lots of conflict resolution and all the answers that involved git show proved to not show what I wanted. The only way I could reliably check which files had conflicts solved manually was to redo the merge locally. Clearly there must be a better way.

Henrique Jung
  • 1,408
  • 1
  • 15
  • 23
  • Git doesn't record any such metadata, the merge commit just contains the resolved tree and pointers to the parent commits. – ephemient Oct 04 '20 at 20:14
  • Use `git show -m` to get a diff against each of the two parents of the merge. (And/or, see [jthill's answer](https://stackoverflow.com/a/64199454/1256452).) – torek Oct 04 '20 at 21:20
  • 2
    With Git 2.36 (Q2 2022), `git log --remerge-diff` will show you what you have done in your merge resolution! See [my answer to this other question](https://stackoverflow.com/a/71181334/6309). – VonC Feb 19 '22 at 00:32

1 Answers1

4
merge=6752364571d0e9c89ddbb3bd287af2e26eb23e59
git checkout $merge^1
git merge $merge^2
git diff $merge

will do it if you're not using auto-reuse of recorded conflict resolutions; if you are, add -c rerere.enabled=false as an git option on the merge.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • Thanks for the answer. I guess redoing the merge locally is the best option. Thanks for providing the commands in a clear way. – Henrique Jung Oct 10 '20 at 13:12