每个文件末尾的额外回车 return 导致合并问题
Extra carriage return at end of every file causing problems in merge
在我们的 git 存储库中,我们的文件有时会在行尾添加额外的回车符 returns。当我查看 vim 中的文件时,我看到了;
<?xml version="1.0" encoding="utf-8"?>^M
<Root>^M
<Child/>^M
</Root>^M
这些额外的 ^M
将出现在文件的每一行中。这在我们合并时会导致问题,因为合并的另一端不会有额外的 ^M
并且我们会遇到很多合并冲突。将忽略白色 space 的选项传递给 git merge
似乎没有帮助,它仍然在整个文件上发生冲突。
我们使用git config core.autoclrf true
.
我需要两件事;
- 如何在我的存储库中搜索所有这些
^M
?这样我就可以使用一些 git ls-files | grep <filter here> | sed 's/^M//'
来摆脱它们。
- 我如何确定它们是如何引入的?
我按照@Biffen 的建议通过使用 unix2dos
(我在 windows)以及链接问题 here.
中的答案解决了这个问题
How to normalize working tree line endings in Git? 的答案非常适合修复 new 提交。 (请参阅公认的技巧和现代 Git 2.16 或更高版本的 git add --renormalize
技巧。)
要更轻松地处理 old 提交,请使用 renormalize 扩展选项:git merge -X renormalize <em>[你想要的其他选项,如果有的话] branch</em>
。这会将您当前的 .gitattributes
设置应用于要合并的每个文件的所有三个版本。
在我们的 git 存储库中,我们的文件有时会在行尾添加额外的回车符 returns。当我查看 vim 中的文件时,我看到了;
<?xml version="1.0" encoding="utf-8"?>^M
<Root>^M
<Child/>^M
</Root>^M
这些额外的 ^M
将出现在文件的每一行中。这在我们合并时会导致问题,因为合并的另一端不会有额外的 ^M
并且我们会遇到很多合并冲突。将忽略白色 space 的选项传递给 git merge
似乎没有帮助,它仍然在整个文件上发生冲突。
我们使用git config core.autoclrf true
.
我需要两件事;
- 如何在我的存储库中搜索所有这些
^M
?这样我就可以使用一些git ls-files | grep <filter here> | sed 's/^M//'
来摆脱它们。 - 我如何确定它们是如何引入的?
我按照@Biffen 的建议通过使用 unix2dos
(我在 windows)以及链接问题 here.
How to normalize working tree line endings in Git? 的答案非常适合修复 new 提交。 (请参阅公认的技巧和现代 Git 2.16 或更高版本的 git add --renormalize
技巧。)
要更轻松地处理 old 提交,请使用 renormalize 扩展选项:git merge -X renormalize <em>[你想要的其他选项,如果有的话] branch</em>
。这会将您当前的 .gitattributes
设置应用于要合并的每个文件的所有三个版本。