如何在git中存储以CR-LF行结尾的文件?

发布于 2024-12-26 12:45:13 字数 320 浏览 0 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初相遇 2025-01-02 12:45:13

仅限 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.

油焖大侠 2025-01-02 12:45:13

我刚刚尝试过这个[Linux; git 版本 2.1.0]
尽我所知,它可以使用以下设置:

$ cat .gitattributes 
.gitattributes  text
.gitignore  text
*.cpp       text
*.h     text

$ cat ~/.gitconfig 
...
[core]
    autocrlf = false
    safecrlf = true
    eol  = crlf

在此配置中,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:

$ cat .gitattributes 
.gitattributes  text
.gitignore  text
*.cpp       text
*.h     text

$ cat ~/.gitconfig 
...
[core]
    autocrlf = false
    safecrlf = true
    eol  = crlf

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 now git add works but now you get a warning for lf-files.

Now rm a checked-in file and reset --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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文