我有一个叫my_pcc_branch。patch的补丁。

当我尝试应用它时,我得到以下信息:

$ git apply --check my_pcc_branch.patch
warning: src/main/java/.../AbstractedPanel.java has type 100644, expected 100755
error: patch failed: src/main/java/.../AbstractedPanel.java:13
error: src/main/java/.../AbstractedPanel.java: patch does not apply

这是什么意思?

我该如何解决这个问题?


当你混合UNIX和Windows git客户端时会发生这种情况,因为Windows并没有“x”位的概念,所以你在Windows下签出的rw-r——r——(0644)文件会被msys POSIX层“提升”为rwx-r-xr-x(0755)。Git认为模式差异与文件中的文本差异基本相同,因此您的补丁不会直接应用。我认为你唯一的选择就是设定核心。文件模式为false(使用git-config)。

以下是msysgit的一些相关信息:http://code.google.com/p/msysgit/issues/detail?id=164(重新路由到archive.org 2013年12月3日的副本)

来自msysgit@googlegroups.com邮件列表的Johannes Sixt建议使用以下命令行参数:

git apply --ignore-space-change --ignore-whitespace mychanges.patch

这解决了我的问题。

Git apply——reject——whitespace=fix mychanges。帕奇为我工作。

解释

——reject选项将指示git在无法确定如何应用补丁时不要失败,而是应用它可以应用的单个块,并为它不能应用的块创建拒绝文件(.rej)。Wiggle可以“应用[这些]被拒绝的补丁,并执行文字差异”。

此外,——whitespace=fix将警告空格错误并尝试修复它们,而不是拒绝应用其他适用的块。

这两个选项一起可以使补丁应用程序在失败时更加健壮,但是它们需要额外关注结果。

完整的文档请参见https://git-scm.com/docs/git-apply。

这个命令将应用补丁不解决它留下坏文件*.rej:

git apply --reject --whitespace=fix mypath.patch

你只需要解决它们。解决后运行:

git -am resolved

当所有这些都失败时,尝试git apply的——3way选项。

git apply——3way patchFile.patch

——3 如果补丁没有完全应用,则返回到3向合并 Patch记录了它应该应用到的blob的身份,而我们 这些斑点是否在本地可用,可能会离开冲突 工作树中供用户解析的文件中的标记。这 选项暗示了——index选项,并且与 ——reject和——cached选项。

典型的失败案例应用尽可能多的补丁,让你在git中解决冲突,但你通常这样做。可能比被拒绝的选择简单一步。

在我的情况下,我很愚蠢,在第一时间就错误地创建了补丁文件,实际上是以错误的方式差分的。我最终得到了完全相同的错误消息。

如果你在master上,git diff branch-name > branch-name。补丁,这试图删除所有你想发生的添加,反之亦然(这是不可能的git完成,因为,显然,从未完成的添加不能删除)。

所以确保你签出到你的分支并执行git diff master > branch-name.patch

尝试使用这里建议的解决方案:https://www.drupal.org/node/1129120

Patch -p1 < example.patch

这对我很有帮助。

警告:此命令可以永久删除旧的丢失提交。在尝试此操作之前,请复制整个存储库。

我找到了这个链接

我不知道为什么这样做,但我尝试了很多工作,这是唯一一个对我有用的。简而言之,运行以下三个命令:

git fsck --full
git reflog expire --expire=now --all
git gc --prune=now

What I looked for is not exactly pointed out in here in SO, I'm writing for the benefit of others who might search for similar. I faced an issue with one file (present in old repo) getting removed in the repo. And when I apply the patch, it fails as it couldn't find the file to be applied. (so my case is git patch fails for file got removed) '#git apply --reject' definitely gave a view but didn't quite get me to the fix. I couldn't use wiggle as it is not available for us in our build servers. In my case, I got through this problem by removing the entry of the 'file which got removed in the repo' from patch file I've tried applying, so I got all other changes applied without an issue (using 3 way merge, avoiding white space errors), And then manually merging content of file removed into where its moved.

我的问题是,我运行git diff,然后运行git reset—hard HEAD,然后意识到我想撤销,所以我尝试从git diff复制输出到一个文件,并使用git apply,但我得到了一个错误,“补丁不适用”。在切换到patch并尝试使用它之后,我意识到由于某种原因,差异的一部分是重复的,在删除重复之后,patch(大概也包括git apply)工作了。

Git apply——reverse——reject example.patch

当你创建一个分支名称颠倒的补丁文件时:

ie。Git diff feature_branch..Master而不是git diff Master ..feature_branch

如果补丁只应用了部分,而不是整个补丁。在应用补丁时,请确保您在正确的目录中。

例如,我在父项目文件夹中创建了一个补丁文件,其中包含.git文件。然而,我试图应用补丁在一个较低的水平。它只是在项目的那个级别应用变更。

只需使用git apply -v示例。补丁要知道“补丁不适用”的原因。然后你可以一个一个地修正它们。