Git merging binary files by hand

For some reason I have problems finding info on dealing with merge conflicts with git when it comes to binary files. Most of the time I know exactly how I want to deal with the conflict, but I always have trouble remembering how to actually accomplish that with git.

The simplest way assuming you don’t want to use mergetool because you don’t have a decent tool that can be trusted with binary is to use git show and then git add then git commit. A slightly clunkier (but simpler?) method is to do the git show then do a git mergetool but exit without saving, confirming the change worked though.

As usual the git help and general messages are the most useful reference. From the git help merge for the information about merging. Assuming I had a conflict with a file called t/test.db.

git show :1:t/test.db # show the common ancestor
git show :2:t/test.db # show the HEAD version (i.e yours)
git show :3:t/test.db # shows the MERGE_HEAD version (i.e. the one you just tried to merge in).

So assuming I wanted to take the one I just merged in I’d do this,

git show :3:t/test.db > t/test.db
git add t/test.db
git status # this perversely now says there is nothing to check in 
git commit # do it without a message and it’ll do a default merge one for you.

The alternative simpler but more perverse way to do it is to replace the git add onwards with git mergetool, and run through that flow, obviously not doing anything in the actual merge tool.

Of course doing this by hand isn’t exclusively for binary files, you can do the same things with your text file. Personally I don’t think I’ve found the need though, hence my trouble remembering how to deal with things this way when I do need to.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s