brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: merge.conflictStyle zdiff3 shows the common ancestor in conflicts

Diff
~/tips/tip-git-zdiff3-conflictstyle

git config --global merge.conflictStyle zdiff3

Adds the original text to merge conflicts so you can see what each side changed.

The default conflict markers show your side and their side, but not the original line both sides started from. Without it I often have to guess who changed what. zdiff3 adds it.

Set it once:

git config --global merge.conflictStyle zdiff3

The conflict then gets a third part after ||||||| with the text from the common ancestor. Take a config file where both branches changed the port and added a line:

host = example.com
<<<<<<< HEAD
port = 8081
||||||| 4b21ade
port = 8080
=======
port = 9090
>>>>>>> feature
retries = 3
timeout = 5

You can see that one side changed 8080 to 8081 and the other changed it to 9090. The retries = 3 line is outside the block because both sides added the same line. The docs say zdiff3 is like diff3 but removes matching lines on the two sides from the conflict region when those lines are near the edge of the region. Plain diff3 would have kept retries = 3 inside both halves, so the block is bigger and you have to compare the two copies yourself.

The caveat is the extra section. A merge tool or editor plugin that expects only two parts can get confused by it, so try one conflict with your usual tool before you set this globally. You can also run a single merge with git -c merge.conflictStyle=zdiff3 merge feature.

Further reading: git-config: merge.conflictStyle

More Diff tips diff -r -x .git -x '*.log' one two diff -y -W 100 old.conf new.conf diff -Naur original/ changed/ > fix.patch patch -p1 --dry-run < ../fix.patch diff --strip-trailing-cr windows.txt unix.txt All Diff tips (12) All topics

Link