git、空格错误、静噪和 autocrlf,最终答案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2947653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git, whitespace errors, squelching and autocrlf, the definitive answers
提问by Benjol
Please can you explain about whitespace errors in git, what do they mean, what is 'squelching', and do I need to worry about it?
请你能解释一下 git 中的空白错误,它们是什么意思,什么是“静噪”,我需要担心吗?
(Running msysgit, but with other users on linux).
(运行 msysgit,但与 linux 上的其他用户)。
There is already a 'definitive' answer for autocrlf here(set it to false git config --global core.autocrlf false
)
目前已经是一个autocrlf“明确的”答案在这里(设置为false git config --global core.autocrlf false
)
回答by VonC
Squelchingis initially a function used in telecommunication to set a threshold above which a signal is or isn't alllowed through.
静噪最初是电信中用于设置阈值的功能,高于该阈值允许或不允许信号通过。
In your case, when you see:
在您的情况下,当您看到:
warning: squelched 104 whitespace errors
warning: 109 lines add whitespace errors.
It means: instead of displaying 100+ error messages, it warns you it should have displayed those errors (but it won't, in order to not clutter the output)
这意味着:它不是显示 100 多条错误消息,而是警告您它应该显示这些错误(但它不会显示,以免输出混乱)
I have no definitive recommendations for whitespace policy, except from identifying why they are introduced in the first place.
If your editor doesn't convert the eol (end of lines) characters between Window and Unix, then it means it somehow add or remove automatically whitespaces, which is not always useful.
我对空白政策没有明确的建议,除非首先确定为什么要引入空白政策。
如果您的编辑器没有在 Window 和 Unix 之间转换 eol(行尾)字符,那么这意味着它会以某种方式自动添加或删除空格,这并不总是有用。
A first test (as in this blog post) is to de-activate the policy:
第一个测试(如本博客文章中所示)是停用策略:
git config core.whitespace nowarn
or try
或尝试
git config core.whitespace fix
and see if that facilitates your rebase operations.
看看这是否有助于您的 rebase 操作。
回答by Vince
Here is how to fix "trailing whitespace" errors when using git apply :
以下是在使用 git apply 时修复“尾随空格”错误的方法:
The first thing you need to know is : what is a whitespace error. This is explained on the core.whitespace setting documentation. Basically, git handles several kind of whitespace errors :
您需要知道的第一件事是:什么是空白错误。这在core.whitespace 设置文档中进行了解释。基本上,git 处理几种空格错误:
blank-at-eol
blank-at-eof
space-before-tab
indent-with-non-tab
tab-in-indent
cr-at-eol
trailing whitespaceerror can rise when patching a file using windows style line ending (CRLF).
To avoid this warning, you can either ask git apply
to not show warning :
使用 Windows 样式行结尾 (CRLF) 修补文件时,尾随空白错误可能会增加。为避免此警告,您可以要求git apply
不显示警告:
git apply --whitespace=nowarn fix.patch
or you can edit git configuration on the fly(with -c
) to say "ok git, CR at end of line are fine this time" :
或者您可以即时编辑 git 配置(使用-c
)说“好的 git,这次行尾的 CR 很好”:
git -c core.whitespace=cr-at-eol apply fix.patch
If you want to make it permanent, just edit the git configuration like that :
如果你想让它永久,只需像这样编辑 git 配置:
git config apply.whitespace nowarn
or :
或者 :
git config core.whitespace cr-at-eol
回答by Lulisaurus
After searching for that answer as well and looking into both the git-config and git-apply manuals, I found that
在搜索该答案并查看 git-config 和 git-apply 手册后,我发现
git config apply.whitespace nowarn
deactivates showing the whitespace errors in your current repository.
停用显示当前存储库中的空白错误。
To make it available for all the repositories just add --global
like this:
要使其可用于所有存储库,只需添加--global
如下:
git config --global apply.whitespace nowarn