git am error:“补丁不适用” [英] git am error: "patch does not apply"

查看:168
本文介绍了git am error:“补丁不适用”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用git将几个提交从一个项目移动到第二个,类似的提交。



所以我创建了一个包含5个提交的补丁:

  git format-patch 4af51 --stdout> changes.patch 

然后将补丁移动到第二个项目的文件夹并且想要应用补丁:

  git am changes.patch 

...但它给了我错误:

 应用:固定产品按订购汇总排序。 
错误:修补程序失败:index.php:17
错误:index.php:修补程序不适用
修补程序在0001失败固定产品按顺序汇总排序。
失败补丁的副本见于:
c:/.../ project2 / .git / rebase-apply / patch
当你解决了这个问题时,运行git am - 继续。
如果您不想跳过此修补程序,请运行git am --skip。
要恢复原始分支并停止修补,请运行git am --abort。

所以我打开了index.php,但没有改变。我假设有一些>>>>>>>< / code>标记等,就像解决合并冲突一样,但文件中没有标记冲突。 git status 给了我空的变更文件列表(只有 changes.patch 在那里)。所以我运行 git am --continue ,但出现了另一个错误:

 应用:固定产品订购汇总。 
没有变化 - 你忘了使用'git add'吗?
如果没有剩下任何东西,那么有可能是其他
已经引入了相同的变化;你可能想跳过这个补丁。
当你解决这个问题时,运行git am --continue。
如果您不想跳过此修补程序,请运行git am --skip。
要恢复原始分支并停止修补,请运行git am --abort。

我使用Windows 7和最新的git版本1.9.4.msysgit.1



PS经过几个小时的搜索后,我发现了一些解决方案,但没有为我工作:




  git am -3 changes.patch 

会给出奇怪的sha1信息错误:

 应用:固定产品订购顺序摘要。 
致命:sha1信息缺乏或无用(index.php)。
版本库缺少必要的Blob以支持3路合并。
不能回退到三路合并。
修补程序在0001失败修复了订单总结订购的产品。
失败补丁的副本见于:
c:/.../ project2 / .git / rebase-apply / patch
当你解决了这个问题时,运行git am - 继续。
如果您不想跳过此修补程序,请运行git am --skip。
要恢复原始分支并停止修补,请运行git am --abort。






  git am changes.patch --ignore-whitespace --no-scissors --ignore-space-change 

给出第一个错误,如上所示:error:patch failed:index.php:17,但在 index.php 中没有冲突标记。

解决方案

什么是补丁?



(请参阅下文),而不是一系列指示:在此添加,将其删除,将此第三项更改为第四项。这就是为什么 git告诉你:


 补丁的副本失败:
c:/.../ project2 / .git / rebase-apply / patch




您可以在您最喜欢的查看器或编辑器中打开该补丁,在您喜欢的编辑器中打开要更改的文件,然后手动补丁,使用你知道(和git不)如何在这里添加这个是如何做的,当待改变的文件现在看起来很少或什么都不像当他们改变时,他们做了一些改变,把这些改变作为补丁发送给你。



多一点



三向合并引入的信息比简单的一系列指令更多一点:它告诉你该文件的原始版本是什么。如果您的存储库具有原始版本,那么您的git可以比较对文件所做的事情,以及补丁对文件所做的描述。



正如你在上面看到的,如果你要求三路合并,git在其他仓库找不到原始版本,所以它甚至不能尝试三路合并。因此,您不会遇到冲突标记,您必须手动执行修补程序。

当你必须手动应用这个补丁时,git仍然有可能适用大部分 您可以自动为您提供修补程序,并且只能向实体提供几件,并能够推理代码(或者需要修补的任何代码)。添加 - reject 会告诉git这样做,并将修补程序的不适用部分保留在拒绝文件中。 如果您使用此选项,则必须手动应用每个发生故障的补丁,并找出如何处理被拒绝的部分。



一次你已经做了必要的修改,你可以 git add 修改过的文件并使用 git am --continue 告诉git如果没有什么可做的事情

从什么时候开始?我们没有你的代码,我不知道这是否是这种情况,但有时候,你会发现其中一个补丁说明了一些相当重要的事情,例如,当修复第42行的单词拼写时在这种情况下,你在查看补丁和当前代码时应该对自己说:aha, 这个补丁应该完全跳过!这就是当你使用已经打印的其他建议git时:


 如果您不想跳过此修补程序,改为运行git am --skip。 


如果您运行 git am - 跳过,git会跳过该补丁,这样如果邮箱中有五个补丁,它最终只会添加四个提交,而不是五个(如果跳过两次,等等)。


I am trying to move several commits from one project to the second, similar one, using git.

So I created a patch, containing 5 commits:

git format-patch 4af51 --stdout > changes.patch

Then move the patch to second project's folder and wants to apply the patch:

git am changes.patch 

...but it gives me error:

Applying: Fixed products ordering in order summary.
error: patch failed: index.php:17
error: index.php: patch does not apply
Patch failed at 0001 Fixed products ordering in order summary.
The copy of the patch that failed is found in:
   c:/.../project2/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

So I opened the index.php, but nothing changed there. I assume some >>>>>>> marks etc., like when resolving merge conflict, but no conflict was marked in the file. git status gave me also empty list of changed files (only changes.patch was there). So I run git am --continue, but another error appears:

Applying: Fixed products ordering in order summary.
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort". 

I am using Windows 7 and newest git version "1.9.4.msysgit.1"

P.S. After few hours of googling, I found few solutions, but nothing works for me:


git am -3 changes.patch 

gives strange "sha1 information" error:

Applying: Fixed products ordering in order summary.
fatal: sha1 information is lacking or useless (index.php).
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001 Fixed products ordering in order summary.
The copy of the patch that failed is found in:
   c:/.../project2/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort". 


git am changes.patch --ignore-whitespace --no-scissors --ignore-space-change

gives first error as above: "error: patch failed: index.php:17", but no conflict marks in index.php was added.

解决方案

What is a patch?

A patch is little more (see below) than a series of instructions: "add this here", "remove that there", "change this third thing to a fourth". That's why git tells you:

The copy of the patch that failed is found in:
c:/.../project2/.git/rebase-apply/patch

You can open that patch in your favorite viewer or editor, open the files-to-be-changed in your favorite editor, and "hand apply" the patch, using what you know (and git does not) to figure out how "add this here" is to be done when the files-to-be-changed now look little or nothing like what they did when they were changed earlier, with those changes delivered to you as a patch.

A little more

A three-way merge introduces that "little more" information than the plain "series of instructions": it tells you what the original version of the file was as well. If your repository has the original version, your git can compare what you did to a file, to what the patch says to do to the file.

As you saw above, if you request the three-way merge, git can't find the "original version" in the other repository, so it can't even attempt the three-way merge. As a result you get no conflict markers, and you must do the patch-application by hand.

Using --reject

When you have to apply the patch by hand, it's still possible that git can apply most of the patch for you automatically and leave only a few pieces to the entity with the ability to reason about the code (or whatever it is that needs patching). Adding --reject tells git to do that, and leave the "inapplicable" parts of the patch in rejection files. If you use this option, you must still hand-apply each failing patch, and figure out what to do with the rejected portions.

Once you have made the required changes, you can git add the modified files and use git am --continue to tell git to commit the changes and move on to the next patch.

What if there's nothing to do?

Since we don't have your code, I can't tell if this is the case, but sometimes, you wind up with one of the patches saying things that amount to, e.g., "fix the spelling of a word on line 42" when the spelling there was already fixed.

In this particular case, you, having looked at the patch and the current code, should say to yourself: "aha, this patch should just be skipped entirely!" That's when you use the other advice git already printed:

If you prefer to skip this patch, run "git am --skip" instead.

If you run git am --skip, git will skip over that patch, so that if there were five patches in the mailbox, it will end up adding just four commits, instead of five (or three instead of five if you skip twice, and so on).

这篇关于git am error:“补丁不适用”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆