消除Git diff中^M的差异

在Windows上把一个刚commit的文件夹上传到了Ubuntu。在Ubuntu上使用git status查看,发现很多文件都被红色标注,表示刚刚修改未add。在Windows上明明是working tree clean,同一个文件夹用FTP传到了Ubuntu,怎么会修改文件内容呢?

于是,用git diff查看文件差异,每一行结尾都有^M标注。百度了一下,了解了原因:

GitHub的帮助网站上给出了一种**解决方案**:

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto # Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text # Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
*.css text eol=crlf
*.js text eol=crlf
*.md text eol=crlf
*.txt text eol=crlf
*.sql text eol=crlf
*.php text eol=crlf # Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
05-22 03:31