我有一个 git 存储库集,包含 core.eol=crlf
、core.autocrlf=true
和 core.safecrlf=true
。
当我应用另一个 crlf
存储库的补丁并应用到我的存储库时,受影响文件的所有行结尾都更改为 lf
。目前我正在这样应用补丁:
git apply --ignore-whitespace mychanges.patch
(看来我必须使用--ignore-whitespace
才能成功应用补丁。)
我目前的解决方法是在文件上运行 unix2dos
。有没有更好的方法让应用程序符合我的 eol 设置?
最佳答案
检查 Git 2.14.x/2.15(2015 年第 3 季度)问题是否仍然存在
请参阅 commit c24f3ab(2017 年 8 月 19 日)和 commit 2fea9de(2017 年 8 月 13 日)。
(由 Torsten Bögershausen (tboegi
) merge 到 Junio C Hamano -- gitster
--,2017 年 8 月 27 日)
apply
: file committed with CRLF should roundtrip diff and applyWhen a file had been committed with CRLF but now
.gitattributes
says "* text=auto
" (orcore.autocrlf
istrue
), the following does not roundtrip,git apply
fails:
printf "Added line\r\n" >>file &&
git diff >patch &&
git checkout -- . &&
git apply patch
Before applying the patch, the file from working tree is converted into the index format (clean filter, CRLF conversion, ...).
Here, when commited with CRLF, the line endings should not be converted.
关于git - 如何避免 git-apply 更改行结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6308625/