我们的 Mercurial 存储库中有一堆 XML 文件。当我们将这些文件中的更改从一个分支 merge 到另一个分支时,Mercurial 会提示我们的某些 XML 文件是二进制的,并要求我在文件的本地版本和其他版本之间进行选择。
我发现 Mercurial thinks any file with a NULL byte in it is binary,我们的一些 XML 文件被编码为 UTF-16,因此包含大量 NULL 字节。 我的默认 merge 工具是Beyond Compare,它可以处理UTF-16编码的文件。我已经配置了 Mercurial as recommended on the Beyond Compare website ,但是在 merge 期间,Mercurial 说:
tool bcomp can't handle binary
什么给了? 为什么 Mercurial 认为 Beyond Compare 无法 merge 我的文件?
最佳答案
使用 Beyond Compare 作为 merge 程序的推荐 Mercurial 配置如下所示:
[merge-tools]
bcomp.executable = C:\Program Files\Beyond Compare 3\BComp.exe
bcomp.args = $local $other $base $output
bcomp.priority = 1
bcomp.premerge = True
bcomp.gui = True
[ui]
merge = bcomp
根据Mercurial docs on merge tools ,有一个 binary
选项,默认情况下为 False
。 当binary=True
时,它告诉 Mercurial 该工具可以 merge 二进制文件。但是,当我打开该选项时,Mercurial 仍然不会让 Beyond Compare merge XML 文件.
更多的研究发现了预 merge
选项。 当premerge=True
时,Mercurial首先进行内部 merge ,只有在有冲突需要解决时才使用 merge 工具。不幸的是,Mercurial总是失败 merge 二进制文件。当预 merge 失败时,Mercurial 会停止该文件的 merge 并且从不启动 merge 工具。
解决方案似乎是将 premerge
选项设置为 False
。不幸的是,预 merge 非常有帮助,因为 90% 的情况下,没有任何冲突,并且永远不会看到您的 merge 工具。将 premerge 设置为 False
时,每次需要 merge 时,Beyond Compare 都会打开。这变得非常乏味。
为了解决这个问题,我创建了第二个 Beyond Compare merge 工具配置,用于 merge 二进制文件。我将其优先级设置为低于默认的 bcomp 工具,因此只有当主 bcomp 工具失败时才会调用它,这通常仅适用于二进制文件。我将这些行添加到了 Mercurial.ini 文件的 merge-tools
部分:
bcompbin.executable = C:\Program Files (x86)\Beyond Compare 3\BCompare.exe
bcompbin.args = $local $other $base $output
bcompbin.gui = True
bcompbin.premerge = False
bcompbin.binary = True
这样做的副作用之一是 Beyond Compare 将启动以 merge 它无法处理的二进制文件。我还没有遇到过这种情况,所以不知道如何处理。我可能会暂时注释掉我的 bcompbin
merge 工具。
关于xml - 为什么 Mercurial 不将我的 XML 文件与 Beyond Compare merge ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7115749/