Better git conflicts: zdiff3

Christophe Colombier - Apr 1 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .