Make git undo any whitespace-only changes?

后端 未结 5 1432
清歌不尽
清歌不尽 2021-01-31 09:28

Is there an easy way to automatically do a git checkout on any file that only has whitespace changes? I\'m dealing with both Windows and some code generation that\'s run from Ec

5条回答
  •  故里飘歌
    2021-01-31 09:35

    This is most likely a line ending issue; Windows uses CRLF (carriage return + line feed, or \r\n) line endings, whereas most other systems use LF (line feed, or \n). Luckily, Git can normalize files such that they are always stored as LF in the repo, but will be checked out as CRLF on Windows. You can do this by setting core.autocrlf to true on Windows:

    $ git config --global core.autocrlf true
    

    and setting core.autocrlf to input on Mac and Linux:

    $ git config --global core.autocrlf input
    

    More info is available here (scroll down to the section titled core.autocrlf).

提交回复
热议问题