当使用git merge
将主题分支“B”合并到“A”时,我会遇到一些冲突。 我知道使用“B”中的版本可以解决所有冲突。
我知道git merge -s ours
。 但我想要的是像git merge -s theirs
这样的东西。
它为什么不存在? 在与现有git
命令冲突合并后,如何获得相同的结果? ( git checkout
B中每个未合并的文件)
更新:从分支A(合并提交点到树的B版本)丢弃任何东西的“解决方案”不是我想要的。
#1楼
如果你在分支A上做:
git merge -s recursive -X theirs B
测试了git版本1.7.8
#2楼
我从现在开始使用Paul Pladijs的答案。 我发现,你可以做一个“正常”合并,发生冲突,所以你这样做
git checkout --theirs <file>
通过使用来自其他分支的修订来解决冲突。 如果对每个文件执行此操作,则会产生与预期相同的行为
git merge <branch> -s theirs
无论如何,努力比合并策略更多! (这是用git版本1.8.0测试的)
#3楼
这将在现有的baseBranch中合并你的newBranch
git checkout <baseBranch> // this will checkout baseBranch
git merge -s ours <newBranch> // this will simple merge newBranch in baseBranch
git rm -rf . // this will remove all non references files from baseBranch (deleted in newBranch)
git checkout newBranch -- . //this will replace all conflicted files in baseBranch
#4楼
请参阅Junio Hamano广泛引用的答案 :如果您要丢弃已提交的内容,只需丢弃提交内容,或者无论如何都要将其保留在主要历史记录之外。 为什么在将来阅读提交来自无法提供的提交的消息时会困扰每个人?
但有时候有行政要求,或者其他一些原因。 对于那些你真的需要记录没有贡献的提交的情况,你想要:
(编辑:哇,我以前设法弄错了。这个有效。)
git update-ref HEAD $(
git commit-tree -m 'completely superseding with branchB content' \
-p HEAD -p branchB branchB:
)
git reset --hard
#5楼
我解决了我的问题
git checkout -m old
git checkout -b new B
git merge -s ours old
#6楼
较旧版本的git允许您使用“他们的”合并策略:
git pull --strategy=theirs remote_branch
但是这已被删除,正如Junio Hamano (Git维护者)在此消息中所解释的那样。 如链接中所述,您可以这样做:
git fetch origin
git reset --hard origin
但要注意,这与实际合并不同。 您的解决方案可能是您真正想要的选择。
#7楼
当使用git merge在“A”中合并主题分支“B”时,我会遇到一些冲突。 我>知道使用“B”中的版本可以解决所有冲突。
我知道git merge-是我们的。 但我想要的是像git merge> -s他们的东西。
我假设你创建了一个master的分支,现在想要合并回master,覆盖master中的任何旧东西。 当我遇到这篇文章时,这正是我想要做的。 </