DEV Community

Christophe Colombier
Christophe Colombier

Posted on

Better git conflicts: zdiff3

Let's talk about git conflicts.

OK, we hate them ๐Ÿ˜…, but let move on.

You may have faced to the classic way for git to report issue.

Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
or cleanly resolved because both sides changed the same way.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
Enter fullscreen mode Exit fullscreen mode

It's convient, BUT you can have something better by activating this git config setting

git config --global merge.conflictstyle zdiff3
Enter fullscreen mode Exit fullscreen mode

You will find more information in the manual https://git-scm.com/docs/git-merge/2.38.0#_how_conflicts_are_presented

The zdiff3 is a zealous variation of diff3 that exists for a while now.

Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
or cleanly resolved because both sides changed the same way.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
||||||| base:sample.txt
or cleanly resolved because both sides changed identically.
Conflict resolution is hard.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
Enter fullscreen mode Exit fullscreen mode

This mode allows you to get more context about the conflict.

It helped me a lot since I started using last year.

Top comments (2)

Collapse
 
ccoveille profile image
Christophe Colombier

If you want more information I recommend this detailed article

neg4n.dev/blog/understanding-zealo...

Collapse
 
hasibrashid profile image
Hasib Al Rashid

It is a really helpful post! Learned alot from it ๐Ÿ‘