LF 将被 git 中的 CRLF 替换 - 该文件将具有其原始行尾
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30523236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LF will be replaced by CRLF in git -the file will have its original line endings
提问by komal thakkar
LF will be replaced by CRLF in git -the file will have its original line endings what does this mean?
LF 将被 git 中的 CRLF 替换 - 该文件将具有其原始行尾,这是什么意思?
回答by David Deutsch
This usually happens when you are on Windows and either core.autocrlf is set to true, or the .gitattributes contains directives to perform line ending normalizations.
这通常发生在您使用 Windows 并且 core.autocrlf 设置为 true 或 .gitattributes 包含执行行结束规范化的指令时。
The way line ending normalization works (on a Windows machine) is that when you commit a file, git replaces every CRLF with a LF, and when you checkout a file, git replaces every LF with a CRLF. Normally this is all transparent to you, and all you ever see is CRLFs in your working directory. However, if you somehow create a file with just LFs in your working directory, here is what will happen:
行结束规范化的工作方式(在 Windows 机器上)是,当您提交文件时,git 将每个 CRLF 替换为 LF,而当您签出文件时,git 将每个 LF 替换为 CRLF。通常这对您来说都是透明的,您所看到的只是工作目录中的 CRLF。但是,如果您以某种方式在工作目录中创建了一个只有 LF 的文件,将会发生以下情况:
- When committing, git will "convert" the LFs to LFs, i.e. do nothing
- When checking out, git will convert the LFs to CRLFs
- 提交时,git 会将 LF“转换”为 LF,即什么都不做
- 签出时,git 会将 LF 转换为 CRLF
The upshot is, you end up creating a file with just LFs, but from then on you always see CRLFs in it. That is what git is warning you about.
结果是,您最终创建了一个只有 LF 的文件,但从那时起,您总是会在其中看到 CRLF。这就是 git 警告你的。
Assuming that it is a text file we are talking about, you can go ahead and ignore this warning. However, if it is a binary file, it means that git is going to attempt to do line normalizations on it, which will corrupt the file. In that case you need to check your .gitattributes file and see why this is happening.
假设它是我们正在谈论的文本文件,您可以继续忽略此警告。但是,如果它是二进制文件,则意味着 git 将尝试对其进行行规范化,这会损坏文件。在这种情况下,您需要检查您的 .gitattributes 文件并了解为什么会发生这种情况。