git Git合并他们的步骤

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5671387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:21:17  来源:igfitidea点击:

Git merging theirs steps

gitmerge

提问by Dominic Bou-Samra

I am dealing with quite a few binary files generated by a program. Auto merging doesn't work well for these files. What I'd like to do when merging, is quite literally take one copy or the other. It's not ideal, but I think it's the best approach.

我正在处理很多由程序生成的二进制文件。自动合并不适用于这些文件。合并时我想做的就是从字面上复制一份或另一份。这并不理想,但我认为这是最好的方法。

Now my understanding, is that if I wanted to take a file from the branch I'm merging from, and completely discard our version, I should do:

现在我的理解是,如果我想从我正在合并的分支中获取一个文件,并完全放弃我们的版本,我应该这样做:

git merge <branchname>
git checkout --theirs <filename>
git add <filename>
git commit

Is this correct, or am I missing something?

这是正确的,还是我错过了什么?

I'd like to do it without using .gitignore

我想在不使用 .gitignore 的情况下做到这一点

回答by Cascabel

If your goal is indeed to keep one version or the other, then yes, you will want to use:

如果您的目标确实是保留一个版本,那么是的,您将需要使用:

git checkout <--theirs|--ours> <path>
git add <path>

Of course, as you say, it's not ideal. If there's any way you can avoid this, you should. If you can, try to adopt workflow habits which avoid changing those files on divergent branches which will later need to be merged. If the files are generated from tracked content, you really probably do want to ignore them - if you have good reason not to, you might want to generate them from the mergeable tracked content instead, if that's possible.

当然,正如你所说,它并不理想。如果有任何方法可以避免这种情况,那么您应该这样做。如果可以,请尝试采用工作流程习惯,避免更改以后需要合并的不同分支上的文件。如果文件是从跟踪的内容生成的,您可能确实想忽略它们 - 如果您有充分的理由不这样做,您可能希望改为从可合并的跟踪内容生成它们,如果可能的话。

So, explore all your other options before doing this, but if you must, you've got it right.

因此,请在执行此操作之前探索所有其他选项,但如果必须这样做,那么您做对了。

回答by Justin Thomas

Look into using .gitignore to ignore generated files. You may have to do git rm as well.

考虑使用 .gitignore 来忽略生成的文件。您可能还需要执行 git rm 。