如何避免 git-apply 更改行结尾

2024-04-23

我有一个 git repo 设置core.eol=crlf, core.autocrlf=true and core.safecrlf=true.

当我应用另一个补丁时crlf存储库和我的存储库中受影响文件的所有行结尾都更改为lf。目前我正在应用补丁,如下所示:

git apply --ignore-whitespace mychanges.patch

(看来我必须使用--ignore-whitespace以使补丁成功应用。)

我目前的工作是运行unix2dos在文件上。有没有更好的方法让 apply 符合我的 eol 设置?


检查 Git 2.14.x/2.15 中问题是否仍然存在(2015 年第 3 季度)

See commit c24f3ab https://github.com/git/git/commit/c24f3abaceabb590125751a67ec0e32946780ac7 (19 Aug 2017), and commit 2fea9de https://github.com/git/git/commit/2fea9de61857986431982ae89c01c89a2fc10038 (13 Aug 2017) by Torsten Bögershausen (tboegi) https://github.com/tboegi.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit a17483f https://github.com/git/git/commit/a17483fcfe313e9ff5b9b0eb8245605fe7f66ea7, 27 Aug 2017)

apply:使用 CRLF 提交的文件应该往返 diff 并应用

当文件已使用 CRLF 提交时,但现在.gitattributes says "* text=auto" (or core.autocrlf is true),以下不 往返,git apply fails:

printf "Added line\r\n" >>file &&
git diff >patch &&
git checkout -- . &&
git apply patch

在应用补丁之前,工作树中的文件被转换 转换为索引格式(干净过滤器、CRLF 转换等)。
这里,当使用 CRLF 提交时,不应转换行结尾。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何避免 git-apply 更改行结尾 的相关文章

随机推荐