Gl.ib.ly

(glibly); Just another techie blog.

Fixing binary merge conflicts in git

Posted by Tariq • Thursday, September 3. 2009 • Category: Tidbits
Git is an awesome tool for managing your code. However, it does take a while to get used to doing things in git. One question I get asked a bit too often is "how do I resolve binary merge conflicts"? Thankfully this is is pretty easy. I usually run the git mergetool command to allow me to resolve merge conflicts using a graphical interface and then manipulate the resultant files on the command line.

You can specify which editor to use in your ~/.gitconfig file. Favourites are kdiff3, vimdiff, xxdiff, and opendiff. If your on Mac OSX then you may be used to FileMerge, in which case you should be using opendiff in your .gitconfig; see below.

...
[merge]
tool = opendiff
...



So, when you are using mergetool option you will something like:
Normal merge conflict for 'lib/yui/assets/skins/sam/editor-sprite.gif':
{local}: created
{remote}: created
Hit return to start merge resolution tool (opendiff):


I just hit return so the editor opens, it will probably warn you the file is binary. In a separate terminal window navigate to the directory where the file is in and do an ls; you'll see something like what is below:
editor-sprite.gif
editor-sprite.gif.BACKUP.41930.gif
editor-sprite.gif.LOCAL.41930.gif
editor-sprite.gif.REMOTE.41930.gif


In this case editor-sprite.gif.REMOTE.41930.gif is the new file and editor-sprite.gif is the original file. To resolve the conflict just copy the REMOTE file over the original file. In my case it would be cp editor-sprite.gif.REMOTE.41930.gif editor-sprite.gif. However, I use the following one liner to resolve these conflicts more generically.


ls *.REMOTE.* | sed "s/\(\(.*\).REMOTE.*\)/cp \1 \2/g" | sh
 


I have it in shell script in my path so I just run it when I need to resolve these types of conflicts. It just finds files with REMOTE in them and then issues a cp command to copy that file over the original.

Hope this helps!

Outside of git mergetool you can just add the binary files using git add file1 file2 ....

Defined tags for this entry: , , , , , , , ,
Vote for articles fresher than 90 days!
Bookmark Fixing binary merge conflicts in git  at del.icio.us Digg Fixing binary merge conflicts in git Bloglines Fixing binary merge conflicts in git Technorati Fixing binary merge conflicts in git Fark this: Fixing binary merge conflicts in git Bookmark Fixing binary merge conflicts in git  at YahooMyWeb Bookmark Fixing binary merge conflicts in git  at Furl.net Bookmark Fixing binary merge conflicts in git  at blogmarks Stumble It!

0 Trackbacks

  1. No Trackbacks

1 Comments

Display comments as (Linear | Threaded)
  1. Great post, really useful!

    Quick question, how do you handle Xcode project files, such as the project.pbxproj file? It's a text files bit it's advised to treat it as binary.

    With a conflict, do you just select the latest or do you merge with FileMerge?

    Thanks!

Add Comment


Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.