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

标签 git newline eol

我有一个 git 存储库集,包含 core.eol=crlfcore.autocrlf=truecore.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 apply

When a file had been committed with CRLF but now .gitattributes says "* text=auto" (or core.autocrlf is true), 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/

相关文章:

emacs - 如何在 emacs 中删除 ^M

node.js - Git Bash 安装 React-Scripts 时出错 "UNKNOWN: unknown error, scandir ' E :\. ..\node_modules\@babel\.helper-annotate-as-pure.DELETE'"

swift - Xcode 11 及其新框架(如 SwiftUI)是否需要更改为 .gitignore?

php - 在 PHP 中向文件写入新行(换行)

javascript - 为什么我从 textarea 中提取换行符的方式与\r 一起使用

windows - 在 Windows 存储库中使用 Linux 行结尾的 .git/config 语法是什么?

python - 带有引号的Python 2.7.6字符串文字错误

每个用户的 Git 日志和控制

git - hg outgoing (hg out) 或 hg incoming (hg in) 的 git 等价物是什么?

swift - 如何检测多行字符串中每一行的第一个索引?