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

后端 未结 3 1573
野的像风
野的像风 2020-12-13 08:49

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 u

3条回答
  •  忘掉有多难
    2020-12-13 09:20

    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
    

提交回复
热议问题