Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 )

like image 624
Benjol Avatar asked Jun 01 '10 06:06

Benjol


People also ask

What is whitespace error in git?

What are considered whitespace errors is controlled by core. whitespace configuration. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors.

What is a whitespace error?

Whitespace error can be caused by either an unsupported character or symbol being passed to the gateway, or a blank or white space being left in a field. Most commonly, the Whitespace error is caused by characters or symbols that are not supported by global XML code being passed to the gateway.


2 Answers

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.

like image 106
VonC Avatar answered Oct 08 '22 13:10

VonC


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 
like image 44
Vince Avatar answered Oct 08 '22 12:10

Vince