ours
This option forces conflicting hunks to be auto-resolved cleanly by
favoring our version. Changes from the other tree that do not
conflict with our side are reflected to the merge result.
This should not be confused with the ours merge strategy, which does
not even look at what the other tree contains at all. It discards
everything the other tree did, declaring our history contains all that
happened in it.
theirs
This is opposite of ours.
注意:正如手册页所述,"ours"合并策略选项与"ours"合并策略非常不同 .
16
git pull -s recursive -X theirs <remoterepo or other repo>
$ git cherry-pick 1023e24
error: could not apply 1023e24... [Commit Message]
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
$ git merge -Xtheirs topicFoo
CONFLICT (modify/delete): js/search.js deleted in HEAD and modified in topicFoo. Version topicFoo of js/search.js left in tree.
9 回答
您可以使用递归"theirs"策略选项:
git merge --strategy-option theirs
来自man:
注意:正如手册页所述,"ours"合并策略选项与"ours"合并策略非常不同 .
或者,简单地说,对于默认存储库:
If you're already in conflicted state...
如果你已经处于冲突状态,并且你想接受他们所有人:
如果你想做相反的事情:
这是非常激烈的,所以在做之前确保你真的想要像这样擦除所有东西 .
好吧,想象一下我刚才的情景:
你试图
merge
,或者也许是cherry-pick
,然后你就停止了现在,您查看冲突的文件,但您确实不想保留更改 . 在上面的例子中,文件只是我的IDE自动添加的换行符冲突了 . 要撤消更改并接受更改,最简单的方法是:
与此相反(用您的版本覆盖传入版本)是
令人惊讶的是,我在网上很难找到这个答案 .
git pull -X theirs
答案可能会创建一个丑陋的合并提交,或发出一个如果您只想忽略对repo中文件的任何本地修改,例如在应该始终是原始镜像的客户端上,请运行此命令(将
master
替换为您想要的分支):它是如何工作的? git fetch does git pull but without merge . 然后git reset --hard使您的工作树与最后一次提交匹配 . 对repo中文件的所有本地更改都将为discarded,但新的本地文件将保持不变 .
要解决与特定分支中的版本的所有冲突:
因此,如果您已处于合并状态,并且您希望保留冲突文件的主版本:
请注意,有时这将是 not work :
要么
我做了这个,假设 HEAD is ours 和 MERGE_HEAD is theirs
要么:
在我们这样做之后,我们很好:
如果你想了解更多,请在这里查看torek的精彩帖子:git checkout --ours does not remove files from unmerged files list
VS Code (integrated Git) IDE Users:
如果要接受 all the incoming changes in the conflict file ,请执行以下步骤 .
同样地,你可以为 Accept All Both, Accept All Current etc., 等其他选项做
如果我希望master能够反映新主题分支的更改,我发现这种情况很有用 . 我注意到-Xtheirs在某些情况下没有冲突就没合并......例如
在这种情况下,我发现的解决方案是
从topicFoo开始,首先使用-s我们的策略在master中合并,这将创建一个假提交,它只是topicFoo的状态 . $ git merge -s我们的主人
检查创建的合并提交
现在结帐主分公司
合并主题分支,但这次使用-Xtheirs递归策略,现在将为您提供具有topicFoo状态的主分支 .