如何在git中存储带有CR-LF行尾的文件? [英] How to store files with CR-LF line endings in git?
问题描述
我正在Linux下开发软件,该软件将使用仅Windows的编译器进行编译.我希望git将带有CR-LF行尾的文件存储在Linux上的存储库中,以便能够打包源而不将其更改为Windows样式.
I'm developing software under Linux which will be compiled using a Windows-only compiler. I want git to store my files with CR-LF line endings in the repository on Linux to be able to package the sources without changing them to Windows style.
我的.gitattributes
看起来像:
*.cpp eol=crlf
*.h eol=crlf
我也已经尝试过core.eol = crlf
.
但是当我在Linux上进行结帐和提交操作时,git仍在使用LF行结尾.
I also already tried core.eol = crlf
.
But git is still using LF line endings when I do checkouts and commits on Linux.
在Linux上,有什么方法可以使用CR-LF告诉git吗?
Is there any way to tell git using CR-LF on Linux?
推荐答案
我刚刚尝试过[Linux; git版本2.1.0] 据我所知,它可以在以下设置下正常工作:
I just tried this [Linux; git version 2.1.0] And as best as I can see its working with the following settings:
$ cat .gitattributes
.gitattributes text
.gitignore text
*.cpp text
*.h text
$ cat ~/.gitconfig
...
[core]
autocrlf = false
safecrlf = true
eol = crlf
在此配置中,git仅允许crlf文件进入数据库,并在git add
上为lf给出致命错误.
In this configuration, git only allows crlf files into the database and gives a fatal error for lf on git add
.
删除safecrlf
设置,现在git add
可以使用,但是现在您会收到有关lf文件的警告.
Remove the safecrlf
setting and now git add
works but now you get a warning for lf-files.
现在rm
已签入文件,而reset --hard
提供了crlf文件-不论是以lf还是crlf签入.
Now rm
a checked-in file and reset --hard
gives a crlf file -- irrespective of whether it was checked in as lf or crlf.
我怀疑:您已经已经签入了LF文件,现在git正在提供这些文件.
I suspect: You have already checked in LF-files and now git is giving those.
请在新的仓库中尝试使用上述设置 ,并告诉我们是否可行.
Please try with the above settings on a new repo and let us know if it works.
这篇关于如何在git中存储带有CR-LF行尾的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!