My diff contains trailing whitespace - how to get rid of it?

前端 未结 6 1983
孤街浪徒
孤街浪徒 2020-12-30 19:20

I\'ve tried editing a php file in TextWrangler with line endings set to Unix, in NetBeans, and in vim. When I save the diff to a patch and then try to apply it, it gives whi

6条回答
  •  北海茫月
    2020-12-30 19:32

    Are you sure those are hard errors? By default, git will warn about whitespace errors, but will still accept them. If they are hard errors then you must have changed some settings. You can use the --whitespace= flag to git apply to control this on a per-invocation basis. Try

    git apply --whitespace=warn patchname.patch
    

    That will force the default behavior, which is to warn but accept. You can also use --whitespace=nowarn to remove the warnings entirely.

    The config variable that controls this is apply.whitespace.


    For reference, the whitespace errors here aren't errors with your patch. It's a code style thing that git will, by default, complain about when applying patches. Notably, it dislikes trailing whitespace. Similarly git diff will highlight whitespace errors (if you're outputting to a terminal and color is on). The default behavior is to warn, but accept the patch anyway, because not every project is fanatical about whitespace.

提交回复
热议问题