我试图使git不更改任何操作的任何行结束。不幸的是,这样做似乎并不重要。我已经将其简化为下面的测试用例,它有尽可能多的不同机制来禁用此行为。
git config --global core.autocrlf falsegit config --global core.eol crlf (以防万一)git init --shared (然后取消隐藏创建的.git目录).gitignore.gitattributes在存储库中创建一个新的文件* -textgit add .,然后git commit -m "initial commit"工作,例如这。git branch master_recv
document.txtgit add -A,然后是git commit -m "<something>"document.txt仍然包含CRLF (删除它并用--hard重置它返回仍然使用CRLF的版本)new filegit add -A,然后是git commit -m "<something>"document.txt和B的new file都仍然包含CRLFgit pull <remote> master:master_recvdocument.txt已改为LF。添加的文件new file也包含LF。如果B是Windows机器,则不会发生此问题。
发布于 2014-02-20 21:09:19
我想通了。似乎SCP程序正在转换行尾。我注意到这一点,当我试图故意制作一个文件与LF结尾,然后观察到,它似乎作为CRLF下载时。
因为这是我的解决方案,我接受了这个答案,但是未来的人们也应该参考其他的答案来获得更普遍的解决方案。
发布于 2014-02-17 07:09:41
一个简单的解决办法是:
git config --global core.autocrlf false git add --renormalize .如果有自动完成的转换,这意味着回购中存在一个.gitattributes 指令。
使用Git 2.8+ (2016年3月)时,请检查是否仍然存在以下eol转换:
git ls-files --eol发布于 2016-09-13 02:19:02
在您的项目中,应该有一个.gitattributes文件。大多数情况下,它应该如下(或此屏幕截图)所示:
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
# Never modify line endings of our bash scripts
*.sh -crlf
#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.css text
*.html text
*.java text
*.js text
*.json text
*.properties text
*.txt text
*.xml text
# These files are binary and should be left untouched
# (binary is macro for -text -diff)
*.class binary
*.jar binary
*.gif binary
*.jpg binary
*.png binary将* text=auto更改为* text=false以禁用自动处理(请参阅屏幕截图)。
如下所示:

如果您的项目没有.gitattributes文件,那么行结束将由您的git配置来设置。若要更改git配置,请执行以下操作:
转到此目录中的配置文件:

对于TortoiseGIT的用户:自动CrLf转换设置在图形用户界面上,在GIT部分。
https://stackoverflow.com/questions/21822650
复制相似问题