我怎样才能让 git 停止尝试在本地文件中插入 CR?
how can I get git to stop trying to insert CRs in local files?
我一直在尝试许多不同的配置,试图让 git 停止这种情况。我有一个本地文件在源代码库中有 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,所以里面没有CR。这是大约 80 个文件中的一个,因此提交将在 git 历史记录中造成大量不必要的改动。
好的,现在看看 git 差异:
$ 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
(git属性)没有效果,git仍然想插入一个CR 进入 watchr.bat 文件。我家目录中的 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。
解决这个问题的方法是消除 .gitattributes
。我曾尝试在 .gitattributes
中注释掉 * text=auto
,但这显然不是 git 的 "seen"。我的同事删除了那个文件,推了然后我拉了它,"add a bunch of CRs everywhere" 行为突然消失了。
我寻找一种方法让 git 看到新更改的 .gitattributes
(我所做的本地编辑)。找不到任何可以执行此操作的 git 命令,因此我不得不假设 git 会在执行差异时随时检查该文件。似乎并非如此。
也许这是 Windows 上 git 中的错误(因为文件观察器在 Windows 中是冒险的)。
我一直在尝试许多不同的配置,试图让 git 停止这种情况。我有一个本地文件在源代码库中有 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,所以里面没有CR。这是大约 80 个文件中的一个,因此提交将在 git 历史记录中造成大量不必要的改动。
好的,现在看看 git 差异:
$ 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
(git属性)没有效果,git仍然想插入一个CR 进入 watchr.bat 文件。我家目录中的 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。
解决这个问题的方法是消除 .gitattributes
。我曾尝试在 .gitattributes
中注释掉 * text=auto
,但这显然不是 git 的 "seen"。我的同事删除了那个文件,推了然后我拉了它,"add a bunch of CRs everywhere" 行为突然消失了。
我寻找一种方法让 git 看到新更改的 .gitattributes
(我所做的本地编辑)。找不到任何可以执行此操作的 git 命令,因此我不得不假设 git 会在执行差异时随时检查该文件。似乎并非如此。
也许这是 Windows 上 git 中的错误(因为文件观察器在 Windows 中是冒险的)。