I have a binary file in my_branch, and when I need to make changes to it, git will of course not merge it.
So what I do now is:
git checkout my_branch
# make a change to gui.bin
mv gui.bin ~/
git commit -a
mv ~/gui.bin .
git commit -a
# git rebase to 1 commit
git checkout master
git merge my_branch
But is there an easier way?
I’m not quite sure what your test case is driving at. You seem to be moving gui.bin out of the way and then putting it back the way it was…
Often, binary files don’t need to be merged, you just want to chose a definitive version from one place or another. Where they genuinely have to be merged you either need a custom merge tool, or use some sort of editor and lots of manual intervention.
I notice that you use
commit -ain your example. One first step to avoid unnecessary conflicts is to not commit any binaries that might be touched incidentally unless you want to commit them. If you justgit addthe files you need to commit and commit without-athen this will help. Alternatively, if there is just one file that you don’t want to commit you couldadd -uand reset it before making a commit.When you do merge branches that have both change a binary you may want to keep one version and not the other. After a merge where git tells you that their are conflicts in your binary you can tell git to use the version in the branch that you were on like this:
or from the branch that you are merging in like this: