46

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 )

Community
  • 1
  • 1
Benjol
  • 57,639
  • 51
  • 180
  • 252
  • And a 'definitive' answer for whitespace errors [here](http://stackoverflow.com/questions/12396622/what-does-1-line-adds-whitespace-errors-mean-when-applying-a-patch/12396793#12396793). – Mechanical snail Oct 19 '12 at 23:08

3 Answers3

30

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.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • So, something like my editor converting tabs to spaces would show as an error? (Actually, it wasn't a rebase that gave me this message, it was re-applying a stash - it didn't prevent the re-apply, but I wanted to understand the message) – Benjol Jun 01 '10 at 09:43
  • 1
    @Benjol: in this case, the 'squelch' message is there to warn you there will be trouble in future merge situations (merge, rebase, push to, pull from) – VonC Jun 01 '10 at 10:57
  • I"core.whitespace no warn" didn't work for me. Do I have to restart machine or terminal or something? – kakyo Jan 29 '13 at 22:23
  • @kakyo No,but the value should be nowarn (in one word), and not "no warn". – VonC Jan 29 '13 at 22:44
  • I did use one word nowarn (it was probably the spellcheck of safari that messed up my comment). But I still see lots of whitespace related warnings, such as "trailing whitespace". – kakyo Jan 31 '13 at 02:18
  • @kakyo : see my answer below, I think it will help you. – Vince Feb 18 '15 at 16:49
17

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
Vince
  • 2,844
  • 1
  • 25
  • 26
14

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
Lulisaurus
  • 150
  • 1
  • 4
  • `core.whitespace` didn't work for me but `apply.whitespace` worked. In my case, applying a diff was throwing whitespace warnings `git apply file.diff`. – amertkara May 04 '15 at 15:36