在合并时忽略空格 [英] Ignore whitespace when doing a merge in mercurial

查看:106
本文介绍了在合并时忽略空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mercurial中进行合并时,我们遇到了一个问题,其中空格更改导致合并冲突,这些冲突掩盖了我们可能存在的任何实际"冲突,并使合并成为一场噩梦.我们最近采用了一种格式化样式,该样式改变了某些分支中文件的缩进方式,此后几乎就不可能合并.

We're hitting a problem when merging in Mercurial where whitespace changes are causing merge conflicts which mask any "real" conflicts we may have and makes merging a nightmare. We've recently conformed to a formatting style which changed the indentation of files in some branches and merging has become almost impossible since.

例如,尝试:

hg init testrepo
cd testrepo/

echo "This is text." > newfile.txt
hg add newfile.txt
hg commit -m "Created a file."
hg branch newbranch
echo "This is some more text." > newfile.txt
hg commit -m "Changed text in the file."
hg update default
echo "   This is text." > newfile.txt
hg commit -m "Added indentation whitespace."

这将导致两个分支,一个分支具有空白更改,另一个分支具有文本更改:

This results in two branches, one with whitespace changes, the other with textual changes:

@  2     "   This is text".
|    
|
| o  1   "This is some more text."
|/     
|
o  0     "This is text."

在尝试使用hg merge时,出现合并冲突.如果我们在每条线上都有冲突,那么理清真正的"冲突将变得困难且耗时.我更希望合并过程认为好吧,变更集2第1行与父级仅在空白处不同,因此请认为它没有变化.选择变更集1第1行作为合并结果."

When trying an hg merge on this I get a merge conflict. If we have conflicts on every line it becomes difficult and time consuming to sort out the "real" conflicts. What I'd prefer is for the merge process to think "OK, changeset 2 line 1 differs from the parent only in whitespace so consider it unchanged. Pick changeset 1 line 1 as the merged result."

推荐答案

是否忽略空格是您的合并工具做出的选择.您可以配置所有用于Mercural的合并工具,如下所示: MergeToolConfiguration

Ignoring whitespace or not is a choice your merge tool makes. You can configure all manner of merge tools for use with mercurial as shown here: MergeToolConfiguration

Mercurial的内部预合并不会/不能忽略空格,但是如果您的外部合并工具可以,并且仅找到空格更改,它将立即退出,如果发现其他空格更改,则可以隐藏空格更改何时加载.

Mercurial's internal pre-merge won't/can't ignore whitespace, but if your external merge tool does and it finds only whitespace changes it will exit immediately, and if it finds other that whitespace changes it can hide the whitespace changes when it does load.

例如,使用流行的 kdiff3合并工具,您可以启用空白2/3文件合并"设置,并告诉它选择向左还是向右.

For example, with the popular kdiff3 merge tool you'd enable the "White space 2/3-file merge" setting and tell it whether to pick left or right.

Tl; Dr:请在您的合并工具中启用此功能,而不要使用Merurial.

Tl;Dr: turn this on in your merge tool, not in mercurial.

这篇关于在合并时忽略空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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