每种文件类型的Mercurial合并策略 [英] Mercurial merge strategy per file type

查看:79
本文介绍了每种文件类型的Mercurial合并策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部:

我想使用kdiff合并具有特定后缀(例如* .c,*.h)的所有文件,并且我想对具有其他后缀(说* .mdl).这样做的目的是让我对特定的文件类型(例如,不可合并的文件,如配置,自动生成的C,模型等)采用智能合并"类型.

I want to use kdiff to merge all files with a certain suffix (say *.c, *.h) and I want to do two things (turn off premerge and use internal:other) for all files with another suffix (say *.mdl). The purpose of this is to allow me to employ a type of 'clobber merge' for a specific file type (ie: un-mergable files like configurations, auto-generated C, models, etc..)

在我的.hgrc中,我尝试过:

In my .hgrc I've tried:

[merge-tools]
kdiff3=
clobbermerge=internal:other
clobbermerge.premerge = False

[merge-patterns]
**.c = kdiff3
**.h = kdiff3
**.mdl = clobbermerge

,但仍会为所有文件触发kdiff3.有想法吗?

but it still triggers kdiff3 for all files. Thoughts?

对此的扩展是在目录上执行智能合并"-但是一旦清除了文件后缀的语法,该目录就应该很简单.

An extension of this would be to perform a 'clobber merge' on a directory - but once the syntax is clear for a file suffix, the dir should be easy.

推荐答案

合并工具可以使用任何可执行文件.要设置始终用$other覆盖$base的合并工具,可以使用以下命令:

Merge tools can use any executable file. To set up a merge tool which always overwrites $base with $other, you can use the following:

[merge-tools]
clobbermerge.priority = 100
clobbermerge.premerge = False
clobbermerge.args = $other $output
clobbermerge.executable = <copy executable>

在Windows上使用此策略时,存在一个问题.您不能简单地将<copy executable>替换为copy shell命令.由于某种原因,Mercurial无法在此上下文中找到Shell命令.我还没有在* nix上尝试过这个.

When using this strategy on Windows, there is one problem. You cannot simply replace <copy executable> with the copy shell command. For some reason, Mercurial fails to find shell commands in this context. I have not tried this on *nix.

要变通解决此问题,您可以创建一个分发批处理文件来执行复制.它只需要运行:copy %1 %2.一旦放置在PATH上,就可以设置clobbermerge.executable=clobber.bat.

To work around this problem, you can create a distribute a batch file that performs the copy. It simply needs to run: copy %1 %2. Once placed on your PATH, you can set clobbermerge.executable=clobber.bat.

如果已安装kdiff3(Windows上为TortoiseHg附带),则使用如下配置,无需外部批处理文件即可获得相同的结果:

If you have kdiff3 installed (comes with TortoiseHg on Windows), you can get the same results without the external batch file using a configuration like this:

[merge-tools]
clobbermerge.priority = 100
clobbermerge.premerge = False
clobbermerge.args = --auto $base $other $other -o $output
clobbermerge.executable = kdiff3

此配置的关键是args字段:

  • --auto:如果没有冲突,则告诉kdiff3不要打开GUI
  • $base $other $other:告诉kdiff3仅使用$other
  • $output:告诉kdiff3输出文件的名称
  • --auto: tells kdiff3 not to open the GUI if there are no conflicts
  • $base $other $other: tells kdiff3 to only use $other
  • $output: tells kdiff3 the name of the output file

这篇关于每种文件类型的Mercurial合并策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆