git - 执行 git apply 时出现错误 "git diff header lacks filename information when removing 1 leading pathname component "

标签 git git-diff git-apply

我通过命令创建了一个差异文件:

git --no-pager diff --no-index --stat pathA pathB >\diff.log


接下来,我执行了一个命令:

git apply --index --ignore-space-change --ignore-whitespace \diff.log


在执行过程中,我遇到了一个错误:

error: git diff header lacks filename information when removing 1 leading pathname component (line 2138)


第 2138 行导致:

2136 diff --git a/C:\Temp\right_tmp5D66/file.cpp b/file.cpp

2137 new file mode 100644

2138 index 0000000000000000000000000000000000000000..e69de...

2139 diff --git ......


我试过一个命令“git apply --reject ...”但它也没有用。我还添加了忽略 chmod 更改的配置(git config core.fileMode false)并且没有任何更改。

最佳答案

很可能是因为您在 git config 中有此设置(~/.gitconfg):

[diff]
  noprefix = true

因此,您可以将其删除或更改为 false:
git config --global diff.noprefix false

关于git - 执行 git apply 时出现错误 "git diff header lacks filename information when removing 1 leading pathname component ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54011629/

相关文章:

java - 将 Android Studio Java 应用程序上传到 GitHub

git subtree 简化如果从不贡献上游?

eclipse - 如何让Egit记住密码和用户名?

regex - 如何在 git diff 中拆分标点符号上的单词?

git:自特定提交以来*未*更改的行数?

xcode - 为什么源代码管理不检查我的 CocoaPods?

git diff 在文件相同时报告差异

git - 找到补丁适用的第一个或最后一个提交

git apply --reject 与 git apply --3way