有没有“他们的"?版本的“git merge -s ours"? [英] Is there a "theirs" version of "git merge -s ours"?
问题描述
合并主题分支B"时变成A"使用 git merge
,我遇到了一些冲突.我知道使用B"中的版本可以解决所有冲突.
When merging topic branch "B" into "A" using git merge
, I get some conflicts. I know all the conflicts can be solved using the version in "B".
我知道git merge -s ours
.但我想要的是类似 git merge -s theirs
的东西.
I am aware of git merge -s ours
. But what I want is something like git merge -s theirs
.
为什么不存在?在与现有 git
命令发生冲突合并后,如何获得相同的结果?(git checkout
来自 B 的每个未合并的文件)
Why doesn't it exist? How can I achieve the same result after the conflicting merge with existing git
commands? (git checkout
every unmerged file from B)
解决方案"只是丢弃分支 A 中的任何内容(树的 B 版本的合并提交点)并不是我想要的.
The "solution" of just discarding anything from branch A (the merge commit point to B version of the tree) is not what I am looking for.
推荐答案
一个类似的替代方案是 --strategy-option
(简称 -X
)选项,它接受他们的
.例如:
A similar alternative is the --strategy-option
(short form -X
) option, which accepts theirs
. For example:
git checkout branchA
git merge -X theirs branchB
然而,这更等同于 -X ours
而不是 -s ours
.关键的区别在于 -X
执行常规递归合并,使用选定的一侧解决任何冲突,而 -s ours
将合并更改为完全忽略另一侧.
However, this is more equivalent to -X ours
than -s ours
. The key difference being that -X
performs a regular recursive merge, resolving any conflicts using the chosen side, whereas -s ours
changes the merge to just completely ignore the other side.
在某些情况下,使用 -X theirs
而不是假设的 -s theirs
的主要问题是删除文件.在这种情况下,只需使用已删除文件的名称运行 git rm
:
In some cases, the main problem using -X theirs
instead of the hypothetical -s theirs
is deleted files. In this case, just run git rm
with the name of any files that were deleted:
git rm {DELETED-FILE-NAME}
之后,-X theirs
可能会按预期工作.
After that, the -X theirs
may work as expected.
当然,使用 git rm
命令进行实际删除将首先防止冲突发生.
Of course, doing the actual removal with the git rm
command will prevent the conflict from happening in the first place.
这篇关于有没有“他们的"?版本的“git merge -s ours"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!