简体   繁体   English

HEAD + commit 相同的 Git 合并冲突

[英]Git merge conflicts where HEAD + commit are identical

I just ran a git pull origin master and many of the merge conflicts are identical in HEAD and the upstream commit:我刚刚运行了一个git pull origin master并且许多合并冲突在 HEAD 和上游提交中是相同的:

<<<<<<< HEAD
gem 'fuzzy-string-match'
=======
gem 'fuzzy-string-match'
>>>>>>> 50147a3519be5bc883dabce86525ee4f36640b22

There are dozens of files with the same situation, where the before and after are identical.有几十个文件情况相同,前后一致。

Does anyone know what might cause this behavior?有谁知道可能导致这种行为的原因? Or if there's a way to auto-merge these "conflicts"?或者是否有办法自动合并这些“冲突”?

Is because u have 2 head sections git doesn't know wich one is the right one that's why he shows u where conflicts are.是因为你有 2 个头部部分,git 不知道哪一个是正确的,这就是为什么他向你展示冲突所在的原因。 Best way is to work with comments so he knows the difference when u merge.最好的方法是使用评论,这样他就知道合并时的区别。

Resolving merge conflicts automatically In cases when you prefer the work of other developers rather than yours, you can mention the appropriate strategy to resolve the conflicts by giving the preference to other developers' work.自动解决合并冲突 如果您更喜欢其他开发人员的工作而不是您的工作,您可以提及通过优先考虑其他开发人员的工作来解决冲突的适当策略。

git pull -s recursive -X theirs <remoterepo or other repo>

Or, simply, for the default repository:或者,简单地说,对于默认存储库:

git pull -X theirs

If you have already pulled without using the theirs strategy and want to give the preference to the work of other developers in one of the conflicting files, then run the command below:如果您已经在没有使用 theirs 策略的情况下进行了拉取,并且希望在其中一个冲突文件中优先考虑其他开发人员的工作,请运行以下命令:

git checkout --theirs path/to/file

If you are already in a conflicted state and want to give the preference to the work of other developers in all the conflicting files, then run the git checkout and git add commands:如果您已经处于冲突状态,并且希望在所有冲突文件中优先考虑其他开发人员的工作,请运行 git checkout 和 git add 命令:

git checkout --theirs .
git add .

If you give the preference to the code, written by yourself, then you should use --ours , instead of --theirs as follows:如果您优先考虑自己编写的代码,那么您应该使用 --ours ,而不是 --theirs ,如下所示:

git checkout --ours .
git add .

However, this is drastic, so make sure before running it.然而,这很激烈,所以在运行它之前请确保。

You may not use the "."您不能使用“。” and type the file name in place of the dot to checkout.并键入文件名代替点以结帐。

You can also use the recursive --theirs strategy option with git merge:您还可以将递归 --theirs 策略选项与 git merge 一起使用:

git merge --strategy-option theirs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM