Dav*_*ven 5 version-control merge mercurial
我正在尝试从不同的 DVCS 转换为 Mercurial。我发现了一种情况,Mercurial 不允许我做其他 DVCS 认为完全合理的事情。
似乎在 repo 中,其中一位用户习惯于这样工作:
这一切似乎都非常合理。除了在用户测试时主干没有前进,hg 拒绝做最后的合并,用
中止:没有要合并的内容
并--force
没有帮助。
我可以使用以下测试用例复制它:
echo "Test data" > file
hg add file
hg commit file -m "Ancestor"
# rev 0
echo "Trunk" > file
hg commit file -m "Trunk"
# rev 1
hg checkout 0
echo "Branch" > file
hg commit file -m "Branch"
# rev 2
hg merge --tool internal:local 1
hg commit -m "Merge trunk to branch"
# rev 3
hg checkout 1
hg merge --tool internal:local 3 # <--- fails
hg commit -m "Merge branch to trunk"
Run Code Online (Sandbox Code Playgroud)
如果我修改测试以使主干在两次合并之间前进,那么在最终合并主干处现在是新的修订版 4,修订版 3 合并到其中,一切正常。
这显然是完全标准的工作流程——我自己做。那么为什么这不起作用呢?
更新:
此测试用例有效:
echo "Test data" > file
hg add file
hg commit file -m "Ancestor"
hg branch trunk
# rev 0
echo "Trunk" > file
hg commit file -m "Trunk"
# rev 1
hg checkout 0
hg branch branch
echo "Branch" > file
hg commit file -m "Branch"
# rev 2
hg merge --tool internal:local 1
hg commit -m "Merge trunk to branch"
# rev 3
hg checkout 1
hg merge --tool internal:local 3
hg commit -m "Merge branch to trunk"
Run Code Online (Sandbox Code Playgroud)
这与第一个测试用例的代码完全相同,除了主干和分叉现在显式分支而不是仅使用临时头。所有合并和检出都使用与以前相同的修订。显然分支是魔法。
不幸的是,我不能因为其他DVCS在实际代码中使用的分支,是使用临时负责人,没有一个是有任何分支信息。我不想为每个叉子伪造一个分支。
我怎样才能说服 Mercurial 在不使用显式分支的情况下让我这样做?
修订版 3 是修订版 1 的直接祖先。此处没有要合并的并发更改。您需要做的就是hg update 3
。
当您有两个不同的分支并且您希望将双方的更改收集到一个新的公共版本中时,适用合并。在这种情况下,您需要在两个不同版本之间进行三向合并(使用来自它们更大共同祖先的信息)
在您的情况下,有两个不同的版本,没有共同的祖先,只有文件的旧版本和新版本。您只想使用hg update
(update
是用于移动的官方命令,checkout
是它的别名)
我不知道为什么另一个 DVCS 将不涉及任何合并的东西称为“合并”,从而使您感到困惑。
(注意:考虑用于hg log -G
图形的图形输出)
(其他注意:永远不要使用 merge --force 这是一个旧的已弃用标志,它会做一些愚蠢的事情。它被隐藏是hg help merge
有充分理由的)