简体   繁体   English

如何在 Windows 上为本地 git 存储库设置 LF 行结尾?

[英]How can I set LF line endings for local git repository on Windows?

I got one problem with line endings in Git repository.我在 Git 存储库中遇到行尾问题。 I want to build my C++ program for Linux using Docker.我想使用 Docker 为 Linux 构建我的 C++ 程序。 The host system is Windows 10. But the first problem I got stuck with is line endings.主机系统是 Windows 10。但我遇到的第一个问题是行尾。 Windows uses CRLF, but Linux uses LF line endings. Windows 使用 CRLF,但 Linux 使用 LF 行尾。 How can I set my local repository to make LF line endings?如何设置我的本地存储库以制作 LF 行结尾? I tried to set "core.autocrlf = false" and "eol = lf" in git config, but it had no effect.我试图在 git config 中设置“core.autocrlf = false”和“eol = lf”,但没有效果。 How can I resolve the problem with line endings?如何解决行尾问题?

Are you pulling the project onto Linux and building it there because if so you want to leave those configuration changes alone as they should convert line endings to lf.您是否将项目拉到 Linux 上并在那里构建它,因为如果是这样,您希望单独保留这些配置更改,因为它们应该将行尾转换为 lf。

The git configurations are about how line-endings are modified once the changes are committed and pushed to the repository (and then in turn if they're converted when pulling back from the repository). git 配置是关于在提交更改并将更改送到存储库后如何修改行尾(然后在从存储库拉回时反过来转换它们)。 If you've been working on files in CLRF then git won't automatically change files line-endings just because you've changed the config.如果您一直在 CLRF 中处理文件,那么 git 不会因为您更改了配置而自动更改文件行尾。 You should also look at writing new files in lf, most IDEs have ways of doing this.您还应该考虑在 lf 中编写新文件,大多数 IDE 都有这样做的方法。

If you're building on Windows though, provided you committed your files when autoclrf was true, the files within the git project repository should have lf endings, changing autoclrf=false and eol-lf should be enough, you just need to do a hard reset to make git bring your local in sync with the repository.如果你在 Windows 上构建,如果你在 autoclrf 为真时提交了你的文件,git 项目存储库中的文件应该有 lf 结尾,改变 autoclrf=false 和 eol-lf 应该就足够了,你只需要做一个艰难的重置以使 git 使您的本地与存储库同步。

Look at some of the answers here: How do I force git to use LF instead of CR+LF under windows?看看这里的一些答案: 如何强制 git 在 windows 下使用 LF 而不是 CR+LF?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM