Git 应用补丁无声地失败(没有错误但没有任何反应)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24821431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:13:40  来源:igfitidea点击:

Git apply patch fails silently (no errors but nothing happens)

gitpatchmsysgit

提问by sashoalm

I'm trying to apply a patch, and git apply patch doesn't give me any errors:

我正在尝试应用补丁,而 git apply patch 没有给我任何错误:

sashoalm@SASHOALM-PC /c/Workspace/tesseract-git/api (master)
$ git apply ../../commit-d0d9477

sashoalm@SASHOALM-PC /c/Workspace/tesseract-git/api (master)
$

As you can see, no error messages are given. But when I open the history, nothing is committed, and the index is empty. It's as if I haven't issued the git applycommand.

如您所见,没有给出错误消息。但是当我打开历史记录时,什么也没有提交,索引是空的。就好像我没有发出git apply命令一样。

I'm at a loss how to troubleshoot this, since there no errors to Google.

我不知道如何解决这个问题,因为谷歌没有错误。

Edit:I forgot to say, but I'm trying to transplant my patches from a repository of Tesseract, where I got the source without version control, created my own empty git repo, and made some commits. Later I cloned the Tesseract repository using git svn, and now I'm trying to move my patches there.

编辑:我忘了说,但我正在尝试从 Tesseract 的存储库移植我的补丁,在那里我获得了没有版本控制的源代码,创建了我自己的空 git 存储库,并进行了一些提交。后来我使用 克隆了 Tesseract 存储库git svn,现在我试图将我的补丁移到那里。

回答by B_.

I found this while googling for the issue: http://data.agaric.com/git-apply-does-not-work-from-within-local-checkout-unrelated-git-repository

我在谷歌搜索这个问题时发现了这个:http: //data.agaric.com/git-apply-does-not-work-from-within-local-checkout-unrelated-git-repository

git applywill fail to do anything when used within a local checkout of a git repository (other than the one for the project the patch is made for), such as if you are patching a module that is within a site that is in Git version control.

Use patch -p1 < path/file.patchinstead.

git apply在 git 存储库的本地检出中使用时将无法执行任何操作(而不是为该补丁制作的项目),例如,如果您正在修补位于 Git 版本控制中的站点内的模块。

使用patch -p1 < path/file.patch来代替。

回答by Pete

Further to B_'s answer, you might think that using git diff --no-prefixwould mean you don't need to use the -p flag on patch. It appears you would be wrong, at least in the versin of patchI have here (2.5), no -p flag is not the same as -p0. -p0 works.

除了 B_ 的回答之外,您可能认为 usinggit diff --no-prefix意味着您不需要在 上使用 -p 标志patch。看来你是错的,至少在patch我这里 (2.5) 的版本中,没有 -p 标志与 -p0 不同。-p0 有效。