git, whitespace errors, squelching and autocrlf, the definitive answers

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

Please can you explain about whitespace errors in git, what do they mean, what is 'squelching', and do I need to worry about it?

(Running msysgit, but with other users on linux).

There is already a 'definitive' answer for autocrlf here (set it to false git config --global core.autocrlf false )

回答1:

Squelching is 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)

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.

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.



回答2:

Here is how to fix "trailing whitespace" errors when using 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 :

blank-at-eol blank-at-eof space-before-tab indent-with-non-tab tab-in-indent cr-at-eol 

trailing whitespace error 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 :

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 core.whitespace=cr-at-eol apply fix.patch 

If you want to make it permanent, just edit the git configuration like that :

git config apply.whitespace nowarn 

or :

git config core.whitespace cr-at-eol 


回答3:

After searching for that answer as well and looking into both the git-config and git-apply manuals, I found that

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:

git config --global apply.whitespace nowarn 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!