Resolving Merge Conflicts with Binary Files: A Step-by-Step Command Line Guide
The problem
During a git merge or rebase, you see the following merge conflict message:
warning: Cannot merge binary files: <path_to_binary_file>
The fix - TL;DR
You have two options:
Keep the version from your branch:
git checkout --ours <path_to_binary_file>
Take the version from the incoming branch:
git checkout --theirs <path_to_binary_file>
Replace <path_to_binary_file>
with the actual path to the binary file causing the conflict.
After resolving the conflict for the binary file(s), use the command:
git add <path_to_binary_file>
to mark the conflict as resolved.
Once all conflicts are resolved, if this is a rebase flow, you can continue the rebase process:
git rebase --continue
You’re done! 😅
More about this issue
I have written before about using git rebase on my development flow, for managing branches and squashing commits, for example. This past week, during a rebase, I ran into a new (for me!) scenario: warning: Cannot merge binary files 👀
The message is quite clear and it means that Git cannot automatically merge the conflicting binary files. For any regular file, you can inspect and resolve the conflicts in the text editor. With binary files, that is not an option.
In this case, when you have only the command line to resolve this conflict, you can use the flags --ours
or --theirs
to select the exact version that should be kept in the tree.
If you found this helpful, please share this article!
The post “Resolving Merge Conflicts with Binary Files: A Step-by-Step Command Line Guide” was originally published at flaviabastos.ca