本文介绍了git:我如何摆脱“警告:CRLF将被替换为LF”不禁用safecrlf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,我已经读了很多关于行结尾和
的git如何对待他们。顺便说一句,我在Windows上。我创建了
a .gitattributes 文件,并将例如* .txt设置为文本。
当我提交一个.txt文件时,我收到警告:

但我知道。我不需要这个警告。在文本文件中替换行
结尾是我想要的。

现在,将 safecrlf 设置为false会使警告
消失,但读取:

lockquote

如果为true,则使git检查转换CRLF是否可逆
当行尾换算处于活动状态时。 Git将验证
a命令是直接在
还是间接修改工作树中的文件。例如,提交一个文件后跟
检出同一个文件应该在工作树中产生原始文件
。如果对于core.autocrlf的当前
设置,情况并非如此,那么git将会拒绝该文件。


safecrlf 似乎是个好主意。
但是,我不明白为什么把 safecrlf 设置为true
给了我关于我的文本文件的警告;在我看来,
这些是不同的问题 - 文本文件的警告和
检查是否可逆。确实,git不会拒绝我的
文件。



我可以摆脱文本文件的警告,并且仍然有
safecrlf set?或者我误解了一些东西?

解决方案

据我所知,设置 core.safecrlf false 是关闭该警告的 only 方式。



safecrlf 如果您的属性设置正确,通常不是必需的。 safecrlf 的目的是防止在存储库中 混合(或非LF)行尾的文件进行规范化。它真的只能与 core.autocrlf 结合使用(以确保其自动猜测不会破坏任何内容),并且如果您通过 .gitattributes 应该可以关闭所有的功能。


I'm new to git, and I've read a lot about line endings andhow git treats them. I'm on Windows by the way. I have madea .gitattributes file and set for example *.txt to text.When I commit a .txt file, I get the warning:

But I know that. I don't need that warning. Replacing lineendings in text files is what I want.

Now, setting safecrlf to false makes the warningdisappear, but the manual for safecrlf reads:

From that, safecrlf seems like a good idea to have.However, I don't understand why setting safecrlf to truegives me warnings about my text files; it seems to me thatthose are different issues -- the warning on text files andthe checking if reversible. Indeed, git does not reject myfile.

Can I get rid of the warnings for text files, and still havesafecrlf set? Or am I misunderstanding something?

解决方案

As far as I can tell, setting core.safecrlf to false is the only way to turn off that warning.

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 to have 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.

这篇关于git:我如何摆脱“警告:CRLF将被替换为LF”不禁用safecrlf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 19:55