如何在git中存储以CR-LF行结尾的文件?
我正在 Linux 下开发软件,该软件将使用仅限 Windows 的编译器进行编译。我希望 git 将带有 CR-LF 行结尾的文件存储在 Linux 上的存储库中,以便能够打包源代码而不将它们更改为 Windows 样式。
我的 .gitattributes 看起来像:
*.cpp eol=crlf
*.h eol=crlf
我也已经尝试过 core.eol = crlf 。 但是当我在 Linux 上进行签出和提交时,git 仍然使用 LF 行结尾。
有没有办法在 Linux 上告诉 git 使用 CR-LF ?
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.
My .gitattributes
looks like:
*.cpp eol=crlf
*.h eol=crlf
I also already tried core.eol = crlf
.
But git is still using LF line endings when I do checkouts and commits on Linux.
Is there any way to tell git using CR-LF on Linux?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅限 Windows 的编译器是否会被仅限 lf 的行结尾所困扰?如果不是,请将其设置为 false。
您只需在存储库上将 auto crlf 设置为 true 即可为编译器设置工作树。
Does the windows only compiler get tripped up by lf-only line endings? If not, keep it set to false.
you need only to set auto crlf to true on a repo that will get the working tree set up for the compiler.
我刚刚尝试过这个[Linux; git 版本 2.1.0]
尽我所知,它可以使用以下设置:
在此配置中,git 只允许 crlf 文件进入数据库,并在 git add 上为 lf 提供致命错误。
删除
safecrlf
设置,现在git add
可以工作,但现在您会收到有关 lf 文件的警告。现在,
rm
是一个签入的文件,reset --hard
会给出一个 crlf 文件——无论它是作为 lf 还是 crlf 签入的。我怀疑:您已经签入了 LF 文件,现在 git 正在提供这些文件。
请在新的存储库上尝试使用上述设置,并让我们知道它是否有效。
I just tried this [Linux; git version 2.1.0]
And as best as I can see its working with the following settings:
In this configuration, git only allows crlf files into the database and gives a fatal error for lf on
git add
.Remove the
safecrlf
setting and nowgit add
works but now you get a warning for lf-files.Now
rm
a checked-in file andreset --hard
gives a crlf file -- irrespective of whether it was checked in as lf or crlf.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.