git config core.autocrlf 是 true,但我仍然收到警告?

标签 git git-bash line-endings core.autocrlf

我知道 Windows 使用 CRLF,并且最好让 Git 在提交之前将行结尾更改为 LF,并在 checkout 时返回到 CRLF。因此,我将 core.autocrlf 设置为 true。然而,与其他线程所说的相反(例如 this ),我仍然收到此警告:

warning: LF will be replaced by CRLF in [FILE_NAME]. The file will have its original line endings in your working directory.

首先,我认为将 core.autocrlf 设置为 true 应该可以阻止这些警告。其次,Git 不是应该在提交时将 LF 转换为 CRLF,而不是相反吗?

有趣的是,我刚刚提交了许多文件,但只有其中两个(.csproj 和 .cs)收到此警告。

附注我在 Windows 上使用 Git Bash。

最佳答案

that it's good practice to let Git change line endings to LF before committing and back to CRLF when checking out.

是的,但对于 core.autocrlf 来说不是
您应该始终将 core.autocrlf 设置为 false,因为它会尝试转换所有文件(包括非文本文件)的 eol(行尾)

如果您有需要转换的文件,请使用 eol directive in a .gitattributes file .
确保使用latest Git for Windows不过:有一个 bug in Git 2.10 .

话虽这么说,如果您仍然想使用 core.autocrlf,请参阅“Make Git “LF will be replaced by CRLF” warnings go away ”:您可以删除索引并再次 checkout 。

关于git config core.autocrlf 是 true,但我仍然收到警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44223868/

相关文章:

php - 如何更改 fputcsv 使用的行结尾?

file - 在 Lua 中处理 CR 行结尾

git-svn 创建了很多带有@rev 的分支

git - bower ECMDERR 无法执行 git ls-remote --tags,

bash - 统计git项目中所有文件的所有修订

git - .gitignore 带有通配符的文件名

git - stash 提交上的 `WIP` 是什么?

git - git merge origin branchname 有什么作用?

Bash mkdir 和子文件夹

git - 更改 git 存储库的 autocrlf 设置后,如何修复 check out 文件中的行尾?