是什么原因导致 git 应用错误已存在于工作目录中

what causes git apply error already exists in working directory

我正在尝试从一个存储库应用提交并将其应用到其他存储库。为此,我使用 git show 生成 git patch\diff,然后将其通过管道传输到 git apply。对于某些提交,会弹出以下错误

$ git show <hash> | git -C ../other/repo apply
error: .foo.txt: already exists in working directory
  1. 是什么原因导致 git apply 失败?
  2. 如何修复?

git apply 通常不会尝试解决冲突。您似乎有一个已经存在的 .foo.txt 文件,并且补丁预计会 创建 一个,而不是修改现有的 gone。

您可以尝试以下方法:

  1. 删除文件,如果您只需要补丁将创建的文件。
  2. 重命名该文件,应用补丁后,手动解决“新”.foo.txt 与您之前存在的文件之间的任何差异。 (如果您进行任何更改,这可能需要额外提交。)