Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect manual conflict resolution in merge commits where the resolution is performed cleanly using one of the parents

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 <[email protected]>
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.

like image 458
Henrique Jung Avatar asked Oct 15 '25 14:10

Henrique Jung


1 Answers

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.

like image 78
jthill Avatar answered Oct 17 '25 08:10

jthill