Simple cmd line tool to help resolve git merge conflicts.
It shows the changes made in the current branch (HEAD
) vs the changes made in the other branch (MERGE_HEAD
), since their common ancestor.
NOTE: Your repo must be configured for "diff3" conflict style (see below for how to do this).
Doesn’t yet work for conflicts which result in a “Temporary merge branch”, sorry.
Say you have a diff3 conflict which looks like this:
cauliflower
<<<<<<< HEAD
peas
potatoes
||||||| merged common ancestors
peas
=======
>>>>>>> topic
tomatoes
git-conflict
will give you this output:
which makes it obvious that one branch added potatoes
and the other removed peas
, so the resolution should probably be:
cauliflower
potatoes
tomatoes
-
Ensure you have "diff3" conflicts enabled:
$ git config --global merge.conflictstyle diff3
-
Copy the
git-conflict
script to somewhere on your PATH. -
Make sure it’s executable:
$ chmod a+x /path/to/git-conflict
-
Have yourself a merry little conflict:
$ git merge conflicting-branch Auto-merging path/to/conflicting-file-1 CONFLICT (content): Merge conflict in path/to/conflicting-file-1 Auto-merging path/to/conflicting-file-2 CONFLICT (content): Merge conflict in path/to/conflicting-file-2 Auto-merging path/to/conflicting-file-3 CONFLICT (content): Merge conflict in path/to/conflicting-file-3 ...
-
Call
git conflict
with the path of the first conflict.$ git conflict path/to/conflicting-file-1
-
You’ll see a beautiful representation of the first conflict in the file only.
It shows:
- Changes in HEAD since the common ancestor
- Changes in MERGE_HEAD since the common ancestor
-
Fix the conflict in
conflicting-file-1
and save it. -
Repeat until all conflicts in this file are resolved, then continue to
conflicting-file-2
, and so on. -
Commit, push, celebrate.
The output is generated using git diff
. Any additional args you pass to git conflict
will be passed on to git diff
, e.g.:
$ git conflict path/to/file --word-diff=color
Obviously only some options will make sense, as it only diffs a chunk of a file at a time.
NOTE: By default, the --ignore-all-space
option is always added, as this usually makes it easier to work out what’s going on. To disable this behaviour, use the custom --consider-whitespace
option:
$ git conflict path/to/file --consider-whitespace
CC0 / Public domain.