Skip to content

stucox/git-conflict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

git-conflict

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.

Example

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

Installation

  1. Ensure you have "diff3" conflicts enabled:

     $ git config --global merge.conflictstyle diff3
    
  2. Copy the git-conflict script to somewhere on your PATH.

  3. Make sure it’s executable:

     $ chmod a+x /path/to/git-conflict
    

Usage

  1. 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
     ...
    
  2. Call git conflict with the path of the first conflict.

     $ git conflict path/to/conflicting-file-1
    
  3. 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
  4. Fix the conflict in conflicting-file-1 and save it.

  5. Repeat until all conflicts in this file are resolved, then continue to conflicting-file-2, and so on.

  6. Commit, push, celebrate.

Customising the output

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

Licence

CC0 / Public domain.

About

Simple cmd line tool to help resolve git conflicts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages