我一直在尝试很多不同的配置来试图阻止 Git 从插入 CR(回车)。 我有一个本地文件,其源代码中有 LF(不是 CRLF)行结尾 repo :
$ cat -vT Source/watchr.bat
echo OFF
echo ==========================================================
echo ==========================================================
echo The "watchr" command is deprecated.
echo The new command is sidekick.bat
echo " _
echo "| |
echo "| |_ _ _ _ __ ___
注意:没有^M
,所以里面没有CR。
这是大约 80 个文件中的一个,因此提交将创建大量文件
Git 历史中不必要的改动。
现在查看 git diff
的输出:
$ gd -R Source/watchr.bat
+echo OFF^M
+echo ==========================================================^M
+echo ==========================================================^M
+echo The "watchr" command is deprecated.^M
+echo The new command is sidekick.bat^M
+echo " _ ^M
+echo "| | ^M
+echo "| |_ _ _ _ __ ___ ^M
啊,^M
每行。为什么?怎么办?
设置:
$ git config --global core.autocrlf
true
$ git config core.autocrlf
false
$ cat -vT .gitattributes
# Set default behavior to automatically normalize line endings.
* text=
将设置更改为input
(或false
)和auto
(.gitattributes
) 无效。
Git 仍然想在 watchr.bat
文件中插入一个 CR。
我的主目录中的 .gitconfig
也有 autocrlf = true
。
如何阻止 Git 执行此操作?
平台:Git 版本 1.9.5.msysgit.0,Windows 7。
最佳答案
你应该尝试:
git config --global core.autocrlf false
(这是我在“Git on Windows (msysgit) - Unix or DOS line termination”中推荐的)
同时检查本地配置:
git config core.autocrlf false
确保您没有 .gitattribute
with a core.eol
directive这也可以添加 \r\n
eol.
关于git - 如何阻止 Git 在本地文件中插入回车符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27894029/