windows - 尝试提交 Git 文件但得到::fatal: LF 将被 <some file in repo> 中的 CRLF 替换

标签 windows visual-studio git

当我尝试提交一些已更改的文件时,我收到了 TortoiseGit 的以下错误消息

fatal: LF would be replaced by CRLF in <some file in the repo>

现在,在我得到通常的 LF vs CRLF 之前答案,我知道并理解辩论的内容。其次,我还将我的全局设置设置为:

core.autocrlf true

第三,I've got a .gitattributes file .

所以我 - 想 - 确保或文件被迫具有 CRLF .

我不明白的是它在说FATAL并阻止我继续。一个警告?当然!我知道我想做什么吗?我愿意!

我只是想让它静默转换和 STFU

或者,如果它被迫阻止我,有没有办法可以将存储库中的所有文件更新为 CRLF ,所以不再发出此警告?

这些存储库是私有(private)的,因此它们永远不会在 Windows + Visual Studio 之外开发。

我该如何继续?

最佳答案

如果您只想警告而不是 fatal error ,您可能需要将 core.safecrlf 设置为“警告”。

来自 "git config" mange page :

核心.safecrlf

If true, makes git check if converting CRLF is reversible when end-of-line conversion is active. Git will verify if a command modifies a file in the work tree either directly or indirectly.
For example, committing a file followed by checking out the same file should yield the original file in the work tree. If this is not the case for the current setting of core.autocrlf, git will reject the file.
The variable can be set to "warn", in which case git will only warn about an irreversible conversion but continue the operation.

CRLF conversion bears a slight chance of corrupting data.
When it is enabled, git will convert CRLF to LF during commit and LF to CRLF during checkout.
A file that contains a mixture of LF and CRLF before the commit cannot be recreated by git.
For text files this is the right thing to do: it corrects line endings such that we have only LF line endings in the repository.
But for binary files that are accidentally classified as text the conversion can corrupt data.

If you recognize such corruption early you can easily fix it by setting the conversion type explicitly in .gitattributes.
Right after committing you still have the original file in your work tree and this file is not yet corrupted. You can explicitly tell git that this file is binary and git will handle the file appropriately.

Unfortunately, the desired effect of cleaning up text files with mixed line endings and the undesired effect of corrupting binary files cannot be distinguished.
In both cases CRLFs are removed in an irreversible way. For text files this is the right thing to do because CRLFs are line endings, while for binary files converting CRLFs corrupts data.

我更喜欢用 .gitattributes 文件(使用 core.eol 设置,你有)来识别我想要强制 eol 的确切文件或文件类型,并将 autocrlf 设置为 false。

如果文本字段带有混合终止符,这 blog post例如,建议:

If you have Notepad++ installed in your computer, simply follow these steps.

  1. Open the file that is having the Fatal issue.
  2. Click Edit -> EOL Conversion then select Windows Format or to any that you’re having an issue committing.

警告,如果您有 Git 2.17 或 2.18:8462ff4 中引入的回归("convert_to_git(): safe_crlf/checksafe 变成 int conv_flags", 2018-01-13, Git 2.17.0) 回到 Git 2.17循环导致 autocrlf 重写以产生警告消息尽管设置了 safecrlf=false

参见 commit 6cb0912 (2018 年 6 月 4 日)作者:Anthony Sottile (asottile) .
(由 Junio C Hamano -- gitster -- merge 于 commit 8063ff9 ,2018 年 6 月 28 日)

关于windows - 尝试提交 Git 文件但得到::fatal: LF 将被 <some file in repo> 中的 CRLF 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15467507/

相关文章:

git - 如何将 libgit2sharp 与 ssh 传输协议(protocol)一起使用?

git - 在 Jenkins 电子邮件通知中获取多行提交消息

html - 在每个标记属性上换行并在 Visual Studio HTML 代码编辑器中保持对齐

c++ - 如何为非模板类​​定义模板方法?

git 错误 : cannot initialize work tree

c++ - 运算符 "new"仅返回一个类的非本地堆指针?

c# - 创建可重用的项目和解决方案结构

c# - PInvoke 调用 SendMessageW 时出现 ERROR_PROC_NOT_FOUND

.net - 无法在 Windows 7 中安装第三方 Windows 服务

windows - rtlGetVersion 错误的想法至于为什么?