在一台Windows机器上,我使用git add添加了一些文件。 我收到警告说:

LF将被CRLF取代

这种转变的后果是什么?


当前回答

在notepad++中打开文件。 进入菜单编辑→EOL转换。 单击Windows格式。 保存文件。

其他回答

它应该是:

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

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

git config core.autocrlf false

我只是犯了同样的错误。 这是在Windows 10上安装NVM NVM后发生的。

在所有级别设置autoclrf都不起作用。

在CMD中我使用:“git ls-files——eol”

i/lf    w/crlf  attr/             src/components/quotes/ExQuoteForm.js
i/lf    w/lf    attr/             src/components/quotes/HighlightedQuote.js

结论:

我做的文件有不同的结局。

要更改文件和重置,请执行

git config core.autocrlf false
git rm --cached -r .
git reset --hard

尽管:

在一些项目中,我需要删除存储库并重新启动它。

Git有三种模式来处理行结束符:

# This command will print "true" or "false" or "input"
git config core.autocrlf

您可以通过向上面的命令行添加一个额外的true或false参数来设置要使用的模式。

If core.autocrlf is set to true, that means that any time you add a file to the Git repository that Git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit. Whenever you git checkout something, all text files automatically will have their LF line endings converted to CRLF endings. This allows development of a project across platforms that use different line-ending styles without commits being very noisy, because each editor changes the line ending style as the line ending style is always consistently 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.

如果核心。将selflf设置为false,则不会执行任何行结束转换,因此文本文件将按原样检入。这通常是可行的,只要你所有的开发人员都在Linux或Windows上。但根据我的经验,我仍然倾向于得到带有混合行结束符的文本文件,最终导致问题。

作为一名Windows开发人员,我个人倾向于让这个设置打开。

请参阅git-config以获得包含“input”值的更新信息。

在两个不同的操作系统(Linux和Windows)中使用“代码”时,CRLF可能会导致一些问题。

我的Python脚本是在Linux Docker容器中编写的,然后使用Windows的Git Bash推送。它给了我LF将被CRLF取代的警告。我并没有想太多,但当我后来开始写剧本时,它说:

/usr/bin/env: 'python\r':没有这样的文件或目录

现在这个r对你们来说是ramification的意思。Windows在“\n”上方使用“CR”-换行符- \n\r。这是你可能需要考虑的事情。