我一直在尝试各种不同的配置来阻止Git插入CR(回车符)。我有一个本地文件,在源代码库中具有LF(而非CRLF)行尾:
$ 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
,因此其中没有回车符。这是大约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仍然想将CR插入
watchr.bat
文件中。我主目录中的
.gitconfig
也有autocrlf = true
。如何停止Git这样做?
平台:Git版本1.9.5.msysgit.0,Windows 7。
.gitattributes
文件。这与此答案和此答案形成对比,它们都_推荐_使用.gitattributes
。 ~ * ~ * ~ 对于任何来到这里(可能包括我未来的自己)并且有时间进行实验的人,我建议将* text = auto
替换为* -crlf
在.gitattributes
中查看会发生什么。 - Henkedos2unix
一样,Git只能猜测一个文件是否为文本文件。这两个工具有时会做出错误的猜测。 也许这就是你在回答中写的内容? (Windows不能从文件内容中很好地猜测出它的类型。) - Henke