让Mercurial使用自定义合并工具进行自己的合并

时间:2012-04-10 06:49:14

标签: mercurial merge

关于mercurial在进行3way合并时所做的事情的Mercurial文档:

  

默认情况下,Mercurial会尝试对文本进行经典的3向合并   在尝试使用外部工具之前在内部编译文件。

当它调用外部工具时,总是“手动合并”。

并非所有的合并工具都是平等创建的,而且事实证明我选择的合并工具(Araxis Merge)通常能够自动合并3个文件,其中mercurial的内部合并工具无法这样做。

这会导致大合并的情况,其中可能有一堆文件干净地合并,由hg的内部mergetool完成,然后一些其他文件不干净地合并但是如果hg允许我指定其mergetool < / em>的。我发现这使得大合并非常低效,因为你需要上下文切换很多:hg弹出我的合并工具,我认为“哦,darn,冲突”,然后意识到“哦等等,根本没有冲突”

我想知道我是否遗漏了这些内容,或者是否真的没有办法让hg能够使用自定义合并工具来自动尝试合并。

2 个答案:

答案 0 :(得分:1)

我认为你正在寻找一个开关,让Araxis Merge自动关闭,如果它可以自动合并。我查看了command line reference和他们的SCM integration document,但我实际上不确定它会是什么样的转换。你必须自己试验一下。

从Mercurial的观点来看,没有“手动合并”这样的东西。 Mercurial首先尝试在内部合并(所谓的“premerge”步骤),如果失败,它会寻找外部工具。如果该工具的退出代码为零(成功退出),则合并仍然可以全自动。 Mercurial将考虑合并成功并继续下一个文件。根据工具的不同,您根本不会注意到这一点:Mercurial只是在后台运行该工具,并且只有在出现严重的合并冲突时才会提示您执行操作。

答案 1 :(得分:0)

您可以使用Mercurial的自定义合并工具。 help merge-tools显示选择运行工具的顺序:

1. If a tool has been specified with the --tool option to merge or
   resolve, it is used.  If it is the name of a tool in the merge-tools
   configuration, its configuration is used. Otherwise the specified tool
   must be executable by the shell.
2. If the "HGMERGE" environment variable is present, its value is used and
   must be executable by the shell.
3. If the filename of the file to be merged matches any of the patterns in
   the merge-patterns configuration section, the first usable merge tool
   corresponding to a matching pattern is used. Here, binary capabilities
   of the merge tool are not considered.
4. If ui.merge is set it will be considered next. If the value is not the
   name of a configured tool, the specified value is used and must be
   executable by the shell. Otherwise the named tool is used if it is
   usable.
5. If any usable merge tools are present in the merge-tools configuration
   section, the one with the highest priority is used.
6. If a program named "hgmerge" can be found on the system, it is used -
   but it will by default not be used for symlinks and binary files.
7. If the file to be merged is not binary and is not a symlink, then
   "internal:merge" is used.
8. The merge of the file fails and must be resolved before commit.

可在help config找到更多信息 - 查找merge-toolsmerge-patterns