Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I merge a binary file?

Tags:

git

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?

like image 223
Louise Avatar asked Jan 18 '10 22:01

Louise


People also ask

How do you combine binary files?

To combine binary files in Power Query Editor, select Content (the first column label) and select Home > Combine Files. Or you can just select the Combine Files icon next to Content.

How do I open a binary file in Windows 10?

To open the Binary Editor on an existing file, go to menu File > Open > File, select the file you want to edit, then select the drop arrow next to the Open button, and choose Open With > Binary Editor.

How do binary files work?

A binary file is a file whose content is in a binary format consisting of a series of sequential bytes, each of which is eight bits in length. The content must be interpreted by a program or a hardware processor that understands in advance exactly how that content is formatted and how to read the data.

Can you use Git for binary files?

Git LFS is a Git extension used to manage large files and binary files in a separate Git repository. Most projects today have both code and binary assets. And storing large binary files in Git repositories can be a bottleneck for Git users. That's why some Git users add Git Large File Storage (LFS).


1 Answers

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 -a in 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 just git add the files you need to commit and commit without -a then this will help. Alternatively, if there is just one file that you don't want to commit you could add -u and reset it before making a commit.

git add -u
git reset -- dontcommit.dat
git 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:

git checkout --ours binary.dat
git add binary.dat

or from the branch that you are merging in like this:

git checkout --theirs binary.dat
git add binary.dat
like image 92
CB Bailey Avatar answered Sep 21 '22 16:09

CB Bailey