env:

视窗 7 麦克西吉特

当我提交时,它说:

warning: LF will be replaced by CRLF. 

这个警告尾巴是向后的吗? 我在Windows中编辑文件,行尾是CRLF,就像这张图片: git将其更改为LF,用于提交回购。 所以我认为正确的警告是:

warning: CRLF will be replaced by LF. 

当前回答

这是因为Windows上的GitHub Desktop的配置假设CRLF,但文本编辑器可能使用LF。您可以将本地存储库设置改为使用lf。

导航到git repo的根目录,并以完全相同的顺序执行

git config core.eol lf
git config core.autocrlf input

来源:GitHub问题

其他回答

所有这些都假设core. selflf =true

原始错误:

警告:LF将被CRLF取代 该文件在您的工作目录中有其原始的行结束符。

错误应该是什么:

警告:在你的工作目录中,LF将被CRLF取代 文件将在git存储库中有其原始的LF行结束符

解释:

The side-effect of this convenient conversion, and this is what the warning you're seeing is about, is that if a text file you authored originally had LF endings instead of CRLF, it will be stored with LF as usual, but when checked out later it will have CRLF endings. For normal text files this is usually just fine. The warning is a "for your information" in this case, but in case git incorrectly assesses a binary file to be a text file, it is an important warning because git would then be corrupting your binary file.

基本上,以前是LF的本地文件现在在本地具有CRLF

——7月9日更新——

删除了@mgiuca评论的“这是正确和准确的”

= = = = = =

不。它不是谈论您的文件当前与CRLF。而是用LF讨论文件。

它应该是:

警告:(如果你检出/或克隆到另一个文件夹与你当前的核心。自自配置,)LF将被CRLF取代 该文件将在您的(当前)工作目录中有其原始的行结束符。

这张图可以解释它的意思。

这是因为Windows上的GitHub Desktop的配置假设CRLF,但文本编辑器可能使用LF。您可以将本地存储库设置改为使用lf。

导航到git repo的根目录,并以完全相同的顺序执行

git config core.eol lf
git config core.autocrlf input

来源:GitHub问题

我遇到过类似的问题,在windows上使用vscode(v1.57)尝试了其他答案中定义的解决方案,但没有工作。

所以对我来说,以下步骤是有效的:

在根文件夹中有一个名为.editorconfig的文件 打开该文件,将end_of_line = lf修改为end_of_line = CRLF 运行git rm——缓存,警告消失!!

确保在.gitignore文件中添加了不必要的文件或文件夹。

如。 node_modules

如果仍然面对,则运行此命令

git配置——全局核心。autocrlf假的' '