How can I see a "three way diff" for a Git merge conflict?
From git-merge(1),
An alternative style can be used by setting the "merge.conflictstyle" configuration variable to "diff3".
In addition to the
<<<<<<<
,=======
, and>>>>>>>
markers, it uses another|||||||
marker that is followed by the original text. ... You can sometimes come up with a better resolution by viewing the original.
This can be enabled using
git config --global merge.conflictstyle diff3
or right in ~/.gitconfig
file
[merge]
conflictstyle = diff3
A lot of GUI diff/merge tools have a 3 or 4 way merge view. I highly recommend Beyond Compare for resolving merge conflicts. Another (okay) tool is DiffMerge.
You can set up a custom mergetool to use with the git mergetool
command. This is my .gitconfig
configuration for Beyond Compare (Pro edition) and DiffMerge on my Windows machine using msysgit:
[merge]
tool = bc3
[diff]
tool = bc3
[difftool "dm"]
cmd = C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"
[difftool "bc3"]
cmd = "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
[mergetool "bc3"]
cmd = "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
You can read more about various diff/merge tool configurations in the official Linux Kernel Git documentation for git config
.