git apply 失败并显示“补丁不适用”错误

发布于 2024-10-13 09:38:55 字数 378 浏览 9 评论 0原文

我有一个名为 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

这是什么意思?

我该如何解决这个问题?

I have a certain patch called my_pcc_branch.patch.

When I try to apply it, I get following message:

$ 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

What does it mean?

How can I fix this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

空城旧梦 2024-10-20 09:38:55

git apply --reject --whitespace=fix mychanges.patch 对我有用。

说明

--reject 选项将指示 git 在无法确定如何应用补丁时不会失败,而是应用它可以应用的各个块并创建拒绝文件 (.rej< /code>) 对于帅哥来说它不能适用。 Wiggle 可以“应用[这些]被拒绝的补丁并执行逐字差异”。

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

这两个选项一起使补丁的应用更加稳健,以防止失败,但它们需要对结果给予额外的关注。

有关整个文档,请参阅 https://git-scm.com/docs/git-apply。

git apply --reject --whitespace=fix mychanges.patch worked for me.

Explanation

The --reject option will instruct git to not fail if it cannot determine how to apply a patch, but instead to apply the individual hunks it can apply and create reject files (.rej) for hunks it cannot apply. Wiggle can "apply [these] rejected patches and perform word-wise diffs".

Additionally, --whitespace=fix will warn about whitespace errors and try to fix them, rather than refusing to apply an otherwise applicable hunk.

Both options together make the application of a patch more robust against failure, but they require additional attention with respect to the result.

For the whole documentation, see https://git-scm.com/docs/git-apply.

请帮我爱他 2024-10-20 09:38:55

[email protected] 邮件列表中的 Johannes Sixt 建议使用以下命令行参数:

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

这解决了我的问题。

Johannes Sixt from the [email protected] mailing list suggested using following command line arguments:

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

This solved my problem.

静若繁花 2024-10-20 09:38:55

当所有其他方法都失败时,请尝试 git apply--3way 选项

git apply --3way patchFile.patch

--3way
当补丁不能完全应用时,如果
patch 记录了它应该应用的 blob 的身份,我们
让这些 blob 在本地可用,可能会导致冲突
工作树中文件中的标记供用户解析。这
选项暗示了 --index 选项,并且与
--reject 和 --cached 选项。

典型的失败案例会尽可能多地应用补丁,并让您在 git 中解决冲突,无论您通常如何这样做。可能比reject替代方案更容易一步。

When all else fails, try git apply's --3way option.

git apply --3way patchFile.patch

--3way
When the patch does not apply cleanly, fall back on 3-way merge if the
patch records the identity of blobs it is supposed to apply to, and we
have those blobs available locally, possibly leaving the conflict
markers in the files in the working tree for the user to resolve. This
option implies the --index option, and is incompatible with the
--reject and the --cached options.

Typical fail case applies as much of the patch as it can, and leaves you with conflicts to work out in git however you normally do so. Probably one step easier than the reject alternative.

2024-10-20 09:38:55

此命令将应用补丁而不解决它,将错误文件保留为 *.rej

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

您只需解决它们即可。解决后运行:

git -am resolved

This command will apply the patch not resolving it leaving bad files as *.rej:

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

You just have to resolve them. Once resolved run:

git -am resolved
眼眸里的快感 2024-10-20 09:38:55

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

<代码>补丁-p1 < example.patch

这对我有帮助。

Try using the solution suggested here: https://www.drupal.org/node/1129120

patch -p1 < example.patch

This helped me .

娜些时光,永不杰束 2024-10-20 09:38:55

当您混合使用 UNIX 和 Windows git 客户端时会发生这种情况,因为 Windows 并不真正具有“x”位的概念,因此您签出的 rw-r--r-- (0644) 文件位于Windows 被 msys POSIX 层“提升”为 rwx-r-xr-x (0755)。 git 认为模式差异与文件中的文本差异基本相同,因此您的补丁不会直接应用。我认为这里唯一好的选择是将 core.filemode 设置为 false(使用 git-config)。

这是一个包含一些相关信息的 msysgit 问题: http://code.google.com/p/msysgit/issues/detail?id=164(重新路由至 archive.org 2013 年 12 月 3 日的副本)

It happens when you mix UNIX and Windows git clients because Windows doesn't really have the concept of the "x" bit so your checkout of a rw-r--r-- (0644) file under Windows is "promoted" by the msys POSIX layer to be rwx-r-xr-x (0755). git considers that mode difference to be basically the same as a textual difference in the file, so your patch does not directly apply. I think your only good option here is to set core.filemode to false (using git-config).

Here's a msysgit issue with some related info: http://code.google.com/p/msysgit/issues/detail?id=164 (rerouted to archive.org's 3 Dec 2013 copy)

我很坚强 2024-10-20 09:38:55

只需使用 git apply -v example.patch 即可了解“patch does not apply”的原因。然后你就可以一一修复它们。

Just use git apply -v example.patch to know the reasons of "patch does not apply". And then you can fix them one by one.

ㄖ落Θ余辉 2024-10-20 09:38:55

git apply --reverse --reject example.patch

当您创建分支名称相反的补丁文件时:

即。 git diff feature_branch..master 而不是 git diff master..feature_branch

git apply --reverse --reject example.patch

When you created a patch file with the branch names reversed:

ie. git diff feature_branch..master instead of git diff master..feature_branch

oО清风挽发oО 2024-10-20 09:38:55

就我而言,我很愚蠢,一开始就错误地创建了补丁文件,实际上以错误的方式进行了比较。我最终得到了完全相同的错误消息。

如果您在 master 上并执行 git diffbranch-name > branch-name.patch,这会尝试删除您想要发生的所有添加,反之亦然(这对于 git 来说是不可能完成的,因为显然,从未完成的添加无法被删除)。

因此,请确保您签出您的分支并执行 git diff master >分支名称.patch

In my case I was stupid enough to create the patch file incorrectly in the first place, actually diff-ing the wrong way. I ended up with the exact same error messages.

If you're on master and do git diff branch-name > branch-name.patch, this tries to remove all additions you want to happen and vice versa (which was impossible for git to accomplish since, obviously, never done additions cannot be removed).

So make sure you checkout to your branch and execute git diff master > branch-name.patch

书间行客 2024-10-20 09:38:55

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

例如,我在包含 .git 文件的父项目文件夹中创建了一个补丁文件。但是我试图在较低级别应用补丁。它仅在项目的该级别应用更改。

If the patch is only partly applied, but not the entire patch. Make sure you are in the correct directory when applying the patch.

For example I created a patch file in the parent project folder containing the .git file. However I was trying to apply the patch at a lower level. It was only applying changes at that level of the project.

做个ˇ局外人 2024-10-20 09:38:55

确保您:

  1. 从存储库的根目录运行 git apply 命令(很奇怪,但这对我来说是唯一正确的解决方案)
  2. 您正在运行 git apply 不使用 --check 选项(在这种情况下,仅执行检查,但补丁本身不执行应用

希望有帮助!

Make sure you are:

  1. Running the git apply command from the root of the repository (weird, but that was the only correct solution for me)
  2. You are running git apply without --check option (in that case only the check is executed, but the patch itself is not applied)

Hope that helps!

国粹 2024-10-20 09:38:55

我所寻找的内容并没有在此处准确指出,我写这篇文章是为了其他可能搜索类似内容的人的利益。我遇到了一个问题,一个文件(存在于旧存储库中)在存储库中被删除。当我应用补丁时,它失败,因为它找不到要应用的文件。 (所以我的情况是 git patch 因文件被删除而失败)
“#git apply --reject”确实给出了一个视图,但并没有完全让我解决问题。我无法使用 wiggle,因为它在我们的构建服务器中不可用。就我而言,我通过从我尝试应用的补丁文件中删除“在存储库中删除的文件”的条目来解决这个问题,因此我应用了所有其他更改,没有出现问题(使用3路合并,避免空格错误),然后手动将删除的文件内容合并到其移动的位置。

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.

醉殇 2024-10-20 09:38:55

我的问题是我运行了 git diff,然后运行了 git reset --hard HEAD,然后意识到我想撤消,所以我尝试从 git 复制输出diff 到文件中并使用 git apply,但我收到“补丁不适用”的错误。在切换到 patch 并尝试使用它之后,我意识到由于某种原因重复了一部分差异,并且在删除重复项之后patch (大概还有 git apply)有效。

My issue is that I ran git diff, then ran git reset --hard HEAD, then realized I wanted to undo, so I tried copying the output from git diff into a file and using git apply, but I got an error that "patch does not apply". After switching to patch and trying to use it, I realized that a chunk of the diff was repeated for some reason, and after removing the duplicate, patch (and presumably also git apply) worked.

不醒的梦 2024-10-20 09:38:55

就我而言,我试图应用 main 上另一个分支 b 的更改(而不是来自补丁文件)。我收到了同样的错误,唯一的替代自动解决方案是 $ git checkout; -- .

此命令将更新工作目录中的文件以匹配 中的文件,但不会更改 HEAD 指针。这意味着您将保留在当前分支上,但您的文件将与 中的文件匹配。

In my case, I was trying to apply changes from another branch b on main (not from a patch file). I received the same error and the only alternative automatic solution was $ git checkout <branch_name> -- .

This command will update the files in your working directory to match the ones in <branch_name>, but it won’t change your HEAD pointer. This means you’ll stay on your current branch, but your files will match those in <branch_name>.

小…红帽 2024-10-20 09:38:55

在一种情况下,我得到“补丁不适用”,因为当我创建补丁时,

git diff hash1..hash2 > mypatch.diff

我交换了 hash1hash2 的位置,所以我得到了“恢复我的更改”修补。

In one case I got "patch does not apply" because when I created the patch with

git diff hash1..hash2 > mypatch.diff

I exchanged the position of hash1 and hash2, so I got a "revert my changes" patch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文