所以我决定将我们git仓库中所有带有Windows风格换行符的文件转换为Unix风格的换行符。
我按照http://www.git-scm.com/docs/gitattributes#_end_of_line_conversion中的说明进行操作:
echo "* text=auto" >>.gitattributes
rm .git/index # Remove the index to force Git to
git reset # re-scan the working directory
git status # Show files that will be normalized
git add -u
git add .gitattributes
git commit -m "Introduce end-of-line normalization"
我后来意识到,这也改变了应该保留CRLF的*.bat文件。我尝试使用以下.gitattributes
文件再次进行整个过程:
# Default
* text=auto eol=lf
# Windows-only files
*.bat text eol=crlf
这似乎并没有改变git status
的输出结果,批处理文件仍然被标记为“已更改”,即使它们在我的工作副本中是CRLF格式,而.gitattributes
已经将它们设置为这样。看来git只是忽略了带有*.bat
的那一行。使用git show --raw
还向我展示了该文件现在存储为LF而不是CRLF。