如何指定在“hg merge”中使用的合并基?
我正在尝试在复杂的 hg 存储库中进行复杂的合并。我对 Mercurial 选择用作执行合并的“基础”的“最新共享祖先”并不满意。
我想指定我自己选择的特定提交作为基础。
这可能吗?如果可能的话,如何实现?
I'm trying to do a complicated merge in a complicated hg repository. I'm not happy with the "newest shared ancestor" that Mercurial chooses to use as the "base" to perform the merge.
I'd like to specify a specific commit of my own choice to use as base.
Is this possible, and if so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Mercurial 3.0:您现在可以选择祖先作为合并基础。您可以通过设置
merge.preferancestor
来做到这一点。当这有意义时,Mercurial 会告诉您。通过下面的示例,您将看到:Mercurial 3.0 版之前: Lazy Badger 是正确的,您在从命令行使用 Mercurial 时无法选择 Mercurial 所选择的祖先。但是,您可以在内部完成此操作,并且为此编写扩展并不太困难:
将其放入文件中并加载扩展。您现在可以用来
覆盖正常的祖先。正如您所发现的,如果有多个可能的祖先,这确实会产生影响。如果进行交叉合并,就会出现这种情况。您可以使用以下命令创建这样的情况:
该图如下所示:
如果您正常合并,您将获得变更集
eb49ad46fd72
作为祖先,并且文件x
包含:如果您改为使用 hg merge --ancestor 2 您会得到不同的结果:
在这两种情况下,我的 KDiff3 都能够自动处理合并,而不会报告任何冲突。如果我使用“递归”合并策略并选择
e72ddea4d238
作为祖先,那么我会遇到明显的冲突。 Git 默认使用递归合并策略。Mercurial 3.0: You can now select the ancestor to use as a merge base. You do that by setting
merge.preferancestor
. Mercurial will tell you about it when this makes sense. With the example below, you would see:Mercurial before version 3.0: Lazy Badger is correct that you cannot pick the ancestor picked by Mercurial when using it from the command line. However, you can do it internally and it's not too difficult to write an extension for this:
Put this in a file and load the extension. You can now use
to override the normal ancestor. As you've found out, this does make a difference if there are several possible ancestors. That situation arises if you have criss-cross merges. You can create such a case with these commands:
The graph looks like this:
If you merge normally you get changeset
eb49ad46fd72
as the ancestor and the filex
contains:If you instead use
hg merge --ancestor 2
you get a different result:In both cases, my KDiff3 were able to handle the merge automatically without reporting any conflicts. If I use the "recursive" merge strategy and pick
e72ddea4d238
as the ancestor, then I'm presented with a sensible conflict. Git uses the recursive merge strategy by default.Base 只是用作合并工具的另一个输入。如果您在合并工具配置中禁用
premerge
(当不存在冲突时,premerge 会为您做出“明显的选择”)并手动调用合并工具,提供您想要作为本地、远程版本的 3 个修订版本的副本和基础,您可以在合并工具中获得您想要的任何内容。合并中实际上只记录左父项和右父项。Base is just used as another input to your merge tool. If you disable
premerge
in your Merge Tool Configuration (premerge makes the "obvious choices" for you when there are no conflicts) and invoke your merge tool manually providing copies of the 3 revisions you want as local, remote, and base, you can get whatever you want in your merge tool. Only the left parent and right parent are actually recorded in the merge.你做不到。因为最新的共享祖先是合并的真正基础
如果您想执行合并并且不想重新思考(因为您的逻辑基础显示/me/错误的假设和解决方案路径),您可以走克隆-变基-合并-导出-导入补丁路线
You can't do it. Because newest shared ancestor IS real base for your merge
If you want to perform merge and don't want re-think (because your logic-base show /me/ wrong assumptions and solution-path) you can go clone-rebase-merge-export-import patch route