为什么git会关心我的文件中的空白字符? [英] Why does git care about trailing whitespace in my files?

查看:328
本文介绍了为什么git会关心我的文件中的空白字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用什么VCS来担心我放入我的文件中有什么业务?我不明白这里的重点。是git版本控制还是语法检查器?

What business is it of whatever VCS I'm using to worry about what I put in my files? I don't get what the point here is. Is git version control or syntax checker?

推荐答案

这是因为Git的一个常见用途是通过电子邮件发送补丁系列。尾随空格会导致电子邮件出现问题,因此通常会被删除,这意味着在通过电子邮件发送补丁并应用补丁的过程中,任何尾随空格都会丢失。这又意味着如果回购中的行中存在尾随空格,而不是正在应用的修补程序中,则在应用修补程序时,您可能会产生虚假冲突或不属于预期的额外更改。

It is because one of the very common uses for Git is sending patch series via email. Trailing spaces cause trouble in email, and are thus usually stripped out, which means any trailing spaces will be lost in the process of sending the patch via email and applying it. This in turn means that if there are trailing spaces on lines in the repo, but not in the patch being applied, you may get spurious conflicts, or extra changes that weren't intended, when applying a patch.

这个预提交钩子默认启用,但不再是。我似乎误解了; 它从未故意默认启用。正如其他人所指出的那样,这一直是一个样本预先提交的钩子;它曾经被禁用,没有给它执行位,但是这可以很容易搞砸(例如,在Windows上的Cygwin下运行),所以在新版本的Git中(因为一年多前)样品已被禁用,被命名为预commit.sample 。如果你不喜欢这个行为,你可以删除或者移动你的 .git / hooks / pre-commit 来阻止这个钩子执行。你也应该更新你的Git到更近的地方,因为这已经修复了很长时间。

This pre-commit hook used to be enabled by default, but is no longer. It seems I have misremembered; it was never deliberately enabled by default. As others have pointed out, this has always been a sample pre-commit hook; it used to be disabled by not giving it the execute bit, but that's something that can get screwed up fairly easily (for instance, running under Cygwin on Windows), so in newer versions of Git (since over a year ago) the samples have been disabled by being named pre-commit.sample. You can delete or move your .git/hooks/pre-commit to prevent this hook from executing if you don't like the behavior. You should also update your Git to something more recent, as this has been fixed for quite a while.

这篇关于为什么git会关心我的文件中的空白字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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