您可以尝试使用此条目在存储库中添加和提交.gitattributes 文件。
* text eol=crlf
(参考:
https://help.github.com/articles/dealing-with-line-endings/)
Git 总是会在结账时将行尾转换为 CRLF。你应该
将此用于必须保留 CRLF 结尾的文件,即使在 OSX 或 Linux 上也是如此。
插图:
考虑现有 repo 中有 2 个文件(比如 test-repo),每个文件各一行。
file_a.txt
file_b.txt
验证文件结尾为\n。
test-repo (master)$ od -c file_a.txt
0000000 T h i s i s f i l e _ a \n
0000017
test-repo (master)$ od -c file_b.txt
0000000 T h i s i s f i l e _ b \n
0000017
在存储库中添加一个.gitattributes 文件。
test-repo (master)$ vim .gitattributes
添加条目。
* text eol=crlf
提交并推送.gitattributes。
test-repo (master)$ git add -A
warning: LF will be replaced by CRLF in .gitattributes.
The file will have its original line endings in your working directory.
test-repo (master)$ git commit -m "Adding .gitattributes file"
test-repo (master)$ git push
添加一个新文件,并在其中键入一行文本。
test-repo (master)$ vim file_c.txt
验证以\n结尾的文件。
test-repo (master)$ od -c file_c.txt
0000000 T h i s i s f i l e _ c \n
0000017
提交并推送添加的文件。
test-repo (master)$ git add file_c.txt
warning: LF will be replaced by CRLF in file_c.txt.
The file will have its original line endings in your working directory.
test-repo (master)$ git commit -m "Added file_c.txt"
test-repo (master)$ git push
将存储库克隆到磁盘上的另一个目录(例如名称为temp_dir)。请注意,结尾现在是 \r \n 代替 \n。
temp_dir/test-repo (master) $ od -c file_a.txt
0000000 T h i s i s f i l e _ a \r \n
0000020
temp_dir/test-repo (master) $ od -c file_b.txt
0000000 T h i s i s f i l e _ b \r \n
0000020
temp_dir/test-repo (master) $ od -c file_c.txt
0000000 T h i s i s f i l e _ c \r \n
0000020