Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
2 min readGit

Inspect merge conflict fixes with --remerge-diff

git show --remerge-diff redoes a merge and diffs it against the commit, so conflict fixes and extra edits made while resolving become readable.

You open a merge commit in review and want to see what changed during conflict resolution. The default combined diff compares the commit with its parents. A remerge diff compares it with Git’s automatic merge.

In my sandbox repo, main and feature both edited the timeout line in settings.txt, so the merge conflicted. I kept timeout=60. While the file was open I also changed retries from 3 to 9, and I added a line to notes.txt. This excerpt shows the settings.txt hunk.

$ git show HEAD
diff --cc settings.txt
@@@ -1,3 -1,3 +1,3 @@@
  host=localhost
 -timeout=45
 -retries=3
 +timeout=60
- retries=3
++retries=9

The ++ prefix means both parents lack retries=9. That comparison leaves out the automatic merge result. By default, git log -p prints no patch for the merge.

Diff against the automatic merge

--remerge-diff redoes the merge, conflicts and all, and compares that result with the stored commit.

$ git show --remerge-diff HEAD
diff --git a/notes.txt b/notes.txt
@@ -1,2 +1,3 @@
 line one
 line two
+line three
diff --git a/settings.txt b/settings.txt
remerge CONFLICT (content): Merge conflict in settings.txt
@@ -1,7 +1,3 @@
 host=localhost
-<<<<<<< 80994b7 (main: timeout 60)
 timeout=60
-=======
-timeout=45
->>>>>>> 91f2d05 (feature: timeout 45)
-retries=3
+retries=9

This reads as an ordinary patch. The remerge CONFLICT line names the file git could not merge, and the marker lines show up as removals because your commit has none. The two hashes in the markers are the tips of the branches that were merged.

line three in notes.txt is a plain addition to a file that never conflicted. retries=3 becoming retries=9 sits outside the marker block, so it was not part of the conflict at all.

Read it as a checklist

I look at the markers first: the removed lines should be the marker lines and the losing side of the conflict. Anything else, a + line or a - line outside that block, is a change the author made while resolving, and I ask about it.

This works for merges with two parents. Swap HEAD for the hash of a two-parent merge, or use it on a range. Run git log -p --remerge-diff and each merge prints the patch above, while ordinary commits print the patches you already know.

When the stored merge matches Git’s automatic result, the diff is empty. I merged a branch that touched a different file and git show --remerge-diff printed the subject line and no patch.