Git:补丁无法应用 - 缺少 header 信息

Git: patch cannot apply - missing header info

我在尝试使用 git am:

应用补丁时遇到此错误
error: git diff header lacks filename information
when removing 1 leading pathname component (line 9)

补丁是使用 git 自己的 format-patch 命令创建的,没有以任何方式编辑,怎么了?

原来是因为我在 git 差异输出中 禁用了文件名前缀 noprefix = true 在你的 .gitconfig 中)。它们在读取 git diff 输出时没有用,但显然 git 补丁依赖于它们。

您可以通过

检查您的设置
git config --get diff.noprefix

如果 returns true,请尝试使用

禁用该设置
git config --global diff.noprefix false

(如果只想对当前仓库进行更改,可以省略 --global 标志)。

之后生成的补丁对我来说效果很好。