如何合并二进制文件? [英] How do I merge a binary file?

查看:396
本文介绍了如何合并二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在my_branch中有一个二进制文件,当我需要对它进行更改时,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?

推荐答案

我不太清楚你的测试用例正在驾驶。您似乎正在移动gui.bin,然后将其重新放回原状......

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.

我注意到你使用 commit -a 在你的例子中。避免不必要冲突的第一步是不要提交任何可能被偶然碰到的二进制文件,除非你想提交它们。如果你只是 git add 你需要提交并提交的文件,而不需要 -a ,那么这将有所帮助。或者,如果只有一个文件不需要提交,您可以 add -u 并在提交之前重置它。

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

当您将合并的分支同时更改为二进制文件时,您可能需要保留一个版本,而不是其他版本。合并之后git告诉你他们在你的二进制文件中有冲突,你可以告诉git在你使用的分支中使用这个版本:

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

这篇关于如何合并二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆