没有空白冲突的合并 [英] Merging without whitespace conflicts

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

问题描述

我遇到了一个问题,那里有一个大型的提交,它可以改变大约一千行代码,从行尾删除空格,并在制表符之前删除空格。



这个项目也有大约50个pull请求,当我的提交被合并时,这些请求都会发生冲突。有没有什么办法可以设置git,以便在合并未来的提交时,忽略其中一个只是空白变化的冲突?



修改git本身或使用第三方工具是不可能的,但使用钩子是没有问题的。

解决方案

  git merge -Xignore-all-space 

或者(更精确)

  git merge -Xignore-space-change 

应足以在合并期间忽略所有与空间相关的冲突。 git diff

   -  ignore-space-change 




忽略空白量的变化。

This忽略行尾的空格,并认为一个或多个空格字符的所有其他序列是等价的。



   - 忽略所有空间




在比较行时忽略空格。

即使一行有空白,另一行也会忽略差异线没有。


ks1322 在评论中增加了一个很好的建议:


值得与 - no-commit 并在实际提交之前检查合并






OP Callum Macrae 报告说,在这种情况下,合并不会中断,并且提取请求修补程序中包含的尾部空格将应用于本地文件。

然而,OP使用预先提交的钩子来处理所述尾随空格。

(我想有点类似于这一个,也此处引用)。 p>




OP的预提交钩子是在这里引用
$ b


除了删除尾随空格,它还会在制表符之前删除1到3个空格将标签宽度设置为4),并添加EOL。

我已经报告说,添加EOL的代码删除了wi中的文件ndows,但无法复制它。



I've got a problem where I've got a large commit which changes about a thousand lines of code, removing whitespace from the end of lines and removing spaces before tabs.

There are also about 50 pull requests for this project, which will all have conflicts when my commit is merged. Is there any way that git can be set up so that when merging future commits, it ignores conflicts where one of them is just a whitespace change?

Modifying git itself or using a third party tool isn't possible, but using a hook is fine.

解决方案

 git merge -Xignore-all-space

Or (more precise)

 git merge -Xignore-space-change

should be enough to ignore all space related conflicts during the merge.

See git diff:

--ignore-space-change

Ignore changes in amount of whitespace.
This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.

--ignore-all-space

Ignore whitespace when comparing lines.
This ignores differences even if one line has whitespace where the other line has none.

ks1322 adds in the comments a good advice:

It is worth to merge with --no-commit and review the merge before actual commit.


The OP Callum Macrae reports that, in that case, the merge proceed uninterrupted, and the trailing spaces contained in the pull request patches are applied to the local files.
However, the OP uses a pre-commit hook which takes care of said trailing spaces.
(I suppose a bit similar to this one, also referenced here).


The OP's pre-commit hook is referenced here:

In addition to removing trailing whitespace, it removes one to three spaces before tabs (I have tab width set to 4), and adds EOLs.
I've had reports that the code that adds the EOL deletes the file in windows, but haven't been able to replicate it.

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

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