Making Resolving Conflicts in Git Easier

March 10th, 2010 by Xerxes Leave a reply »

One thing that bugs me when using Git, is that resolving merge conflicts isn’t a seamless process. It involves the fiddly task of opening files which conflicted, then resolving the conflict and then staging the changes.

The part which bugs me the most is having to either type the full filename in order to open it in any editor, OR i have to use the mouse to clipboard the filename and then paste it onto the commandline. Just not straightforward enough.

So i knocked up a quick bash script which makes use of git’s ability to create extensions for git commands. This script issues a rebase (i also have one for merge) and will fire off my preferred editor for editing files outside Visual Studio.

#!/bin/bash
# git-resolve-rebase

git rebase $1 
modified=`git status | grep 'unmerged' | uniq`

if [ -n "$modified" ]; then
	git status | grep 'unmerged' | awk '{print $3}' | uniq | xargs -n1 e
fi

(where e is the shell-script to launch E-Text Editor

To use this extension, all i need to do is:

$ (MyBranch)> git resolve-rebase master
Be Sociable, Share!

Related posts:

  1. Making Assumptions About An Objects State I’ve seen this now twice in about 30 mins, and...
  2. Making Sexy CSS Buttons http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html...
  3. Mass Reverse-DNS Lookup I needed to quickly browse through some web-server logs and...
  4. Instant Twitter Bookmark Tonight’s been a busy night for silly coding This first...
  5. BASH – [: too many arguments I’ve been writing a little bash script to wrap up...

3 comments

  1. Paul Batum says:

    Why not just register your preferred diff tool in the git config, and then just use the git mergetool command?

    http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

  2. Xerxes says:

    well fuck…..

    i knew of git difftool, just never realised the equivalent git mergetool.

    cheers!