Resolving a Git conflict with binary files Resolving a Git conflict with binary files git git

Resolving a Git conflict with binary files


git checkout accepts an --ours or --theirs option for cases like this. So if you have a merge conflict, and you know you just want the file from the branch you are merging in, you can do:

$ git checkout --theirs -- path/to/conflicted-file.txt

to use that version of the file. Likewise, if you know you want your version (not the one being merged in) you can use

$ git checkout --ours -- path/to/conflicted-file.txt


You have to resolve the conflict manually (copying the file over) and then commit the file (no matter if you copied it over or used the local version) like this

git commit -a -m "Fix merge conflict in test.foo"

Git normally autocommits after merging, but when it detects conflicts it cannot solve by itself, it applies all patches it figured out and leaves the rest for you to resolve and commit manually. The Git Merge Man Page, the Git-SVN Crash Course or this blog entry might shed some light on how it's supposed to work.

Edit: See the post below, you don't actually have to copy the files yourself, but can use

git checkout --ours -- path/to/file.txtgit checkout --theirs -- path/to/file.txt

to select the version of the file you want. Copying / editing the file will only be necessary if you want a mix of both versions.

Please mark mipadis answer as the correct one.


You can also overcome this problem with

git mergetool

which causes git to create local copies of the conflicted binary and spawn your default editor on them:

  • {conflicted}.HEAD
  • {conflicted}
  • {conflicted}.REMOTE

Obviously you can't usefully edit binaries files in a text editor. Instead you copy the new {conflicted}.REMOTE file over {conflicted} without closing the editor. Then when you do close the editor git will see that the undecorated working-copy has been changed and your merge conflict is resolved in the usual way.