我试图让 git 不更改任何操作的任何行结尾。不幸的是,这样做似乎无关紧要。我已将其简化为以下测试用例,该测试用例具有尽可能多的不同机制来禁用此行为。
- 从两台机器开始(Windows 计算机 = A,Linux 计算机 = B)
- 在两台机器上:
git config --global core.autocrlf false
- 在两台机器上:
git config --global core.eol crlf
(万一)
- Make new repository on A. From an empty folder:
-
git init --shared
(然后取消隐藏创建的.git
目录)
- 制作一个新文件
.gitignore
在存储库中
- 制作一个新文件
.gitattributes
在存储库中使用单行:* -text
-
git add .
, then git commit -m "initial commit"
解决办法,例如this https://github.com/wakatime/sublime-wakatime/issues/15.
git branch master_recv
- 添加遥控器
- 制作一个新文件
document.txt
在包含 CRLF 的存储库中
- Commit:
git add -A
, then git commit -m "<something>"
- 注意A的
document.txt
仍然包含 CRLF (删除它并重置--hard
返回仍带有 CRLF 的版本)
- SCP 将整个目录复制到计算机 B
- 添加新文件
new file
包含 CRLF
- Commit:
git add -A
, then git commit -m "<something>"
- 注意B的
document.txt
和B的new file
两者都仍然包含 CRLF
- 将B的master拉到A:
git pull <remote> master:master_recv
- A's
document.txt
已更改为 LF。添加的文件new file
还包含 LF。
如果 B 是 Windows 计算机,则不会出现该问题。
一种简单的解决方案是:
- make sure core.autocrlf is set to false for all repos:
git config --global core.autocrlf false
-
Git 2.16(2018 年第一季度)及更高版本 https://stackoverflow.com/a/47580886/6309, run
git add --renormalize .
- 否则,重新克隆您的存储库,并检查是否已完成 EOL 转换。
如果有自动完成的转换,则意味着.gitattributes
core.eol指示 https://stackoverflow.com/a/3209806/6309回购协议内有吗?
With Git 2.8+(2016 年 3 月) https://stackoverflow.com/a/35204436/6309,检查是否仍有 eol 转换:
git ls-files --eol
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)