跨平台的情况下,windows和unix的换行符谁不一样的。这个和git结合起来的时候有点烦哈。
如何将git的所有crlf文件转换成lf格式
下面这个脚本可以将库中的所有文件中的crlf去掉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
gitattribute
其中一个重点,可以在git库里面加入.gitattributes文件处理crlf的问题
例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
you’ll notice that files are matched–*.c
, *.sln
, *.png
–, separated by a space, then given a setting–text
, text eol=crlf
, binary
. We’ll go over some possible settings below.
text=auto
Git will handle the files in whatever way it thinks is best. This is a good default option.
text eol=crlf
Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. For example, here is a Windows project that enforces CRLF line endings.
text eol=lf
Git will always convert line endings to LF on checkout. You should use this for files that must keep LF endings, even on Windows. For example, here is a project that enforces LF line endings.
binary
Git will understand that the files specified are not text, and it should not try to change them. The binary setting is also an alias for -text -diff.
另外一个是: Refreshing a repository after changing line endings
这部分和上面第一节是基本一样的内容,(前提是设置了core.autocrlf或.gitattributes文件)
配置core.autocrlf
How core.autocrlf works:
1 2 3 4 5 6 7 8 9 10 11 |
|
tips: 建议搭建使用编辑器的时候,如果是windows下,特别关注一下回车的格式
提交到代码仓库的时候,按照unix的格式提交。例如上面的core.autocrlf=input
。
如果想在checkout的文件为crlf,就设置为core.autocrlf=true