git:如何在不禁用 safecrlf 的情况下摆脱“警告:CRLF 将被 LF 替换”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16873848/
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
git: How do I get rid of "warning: CRLF will be replaced by LF" without disabling safecrlf?
提问by oskarkv
I'm new to git, and I've read a lot about line endings and
how git treats them. I'm on Windows by the way. I have made
a .gitattributes
file and set for example *.txt to text.
When I commit a .txt file, I get the warning:
我是 git 的新手,我已经阅读了很多关于行结尾以及 git 如何对待它们的内容。顺便说一下,我在 Windows 上。我制作了一个.gitattributes
文件并将例如 *.txt 设置为文本。当我提交 .txt 文件时,我收到警告:
warning: CRLF will be replaced by LF in whatever.txt
警告:CRLF 将在whatever.txt 中被 LF 替换
But I know that. I don't need that warning. Replacing line endings in text files is what I want.
但我知道。我不需要那个警告。替换文本文件中的行尾是我想要的。
Now, setting safecrlf
to false makes the warning
disappear, but the manual for safecrlf
reads:
现在,设置safecrlf
为 false 会使警告消失,但手册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.
如果为 true,当行尾转换处于活动状态时,让 git 检查转换 CRLF 是否可逆。Git 将验证命令是否直接或间接修改了工作树中的文件。例如,提交一个文件然后检出同一个文件应该会在工作树中产生原始文件。如果 core.autocrlf 的当前设置不是这种情况,git 将拒绝该文件。
From that, safecrlf
seems like a good idea to have.
However, I don't understand why setting safecrlf
to true
gives me warnings about my text files; it seems to me that
those are different issues -- the warning on text files and
the checking if reversible. Indeed, git does not reject my
file.
safecrlf
由此看来,这似乎是一个好主意。但是,我不明白为什么设置safecrlf
为 true 会给我有关文本文件的警告;在我看来,这些是不同的问题——文本文件上的警告和检查是否可逆。事实上,git 不会拒绝我的文件。
Can I get rid of the warnings for text files, and still have
safecrlf
set? Or am I misunderstanding something?
我可以摆脱文本文件的警告,并且仍然
safecrlf
设置吗?还是我误解了什么?
回答by Jan Krüger
As far as I can tell, setting core.safecrlf
to false
is the onlyway to turn off that warning.
据我所知,设置core.safecrlf
为false
是关闭该警告的唯一方法。
safecrlf
is generally not necessary if your attributes are set correctly. The point of safecrlf
is to prevent normalization in a file that is supposed tohave mixed (or non-LF) line endings in the repository. It's really only useful in combination with core.autocrlf
(to make sure that its automatic guesses can't destroy anything), and if you're setting your own attributes via .gitattributes
it should be okay to turn all that off.
safecrlf
如果您的属性设置正确,则通常不需要。重点safecrlf
是防止在存储库中应该具有混合(或非 LF)行结尾的文件中进行规范化。它实际上仅与core.autocrlf
(以确保其自动猜测不会破坏任何东西)结合使用,并且如果您通过.gitattributes
它设置自己的属性,则可以将其全部关闭。
回答by Ian Mariano
In your .gitattributes
you can:
在.gitattributes
你可以:
# normalize text files to use lf
text eol=lf
# except these which we want crlf
*.txt eol=crlf
回答by o.v
The short answer to your question is NO.
对您问题的简短回答是否定的。
Because, basically, core.safecrlf setting controls "warning level":
因为,基本上,core.safecrlf 设置控制“警告级别”:
- false - proceed without warning
- warn - proceed with warning
- true - don't proceed
- false - 在没有警告的情况下继续
- 警告 - 继续警告
- 真的 - 不要继续
So, you have to choose option that suits you the most.
因此,您必须选择最适合您的选项。
回答by Juca Duarte
use
用
$ git config core.autocrlf false