How to handle git am patch failure

Source: Internet
Author: User

Reference: http://www.cnblogs.com/domainfei/articles/2433504.html

Http://blog.sina.com.cn/s/blog_5372b1a301015y0n.html

Http://www.pizzhacks.com/bugdrome/2011/10/deal-with-git-am-failures/

For example, a typical git am failure may be like this: $ Git am patch Applying: pacth description Error: patch failed: file. C: 137 Error: file. C: patch does not apply Error: patch failed: makefile: 24 Error: libavfilter/makefile: patch does not apply Patches failed at 0001 patch description When you have resolved this problem run "Git am -- resolved ". If you wowould prefer to skip this patch, instead run "Git am -- skip ". To restore the original branch and stop patching run "Git am -- abort ".
As you can see, if a conflict occurs, git only outputs the above information and stops. A small conflict will prevent the whole patch from being integrated.
The easiest way to solve this problem is to first use git am -- abort, then manually add this patch, patch-P1 <patch, and manually solve itCodeConflict, and finally use git commit-a to submit the code. However, you may lose the original commit information (such as from, date, subject, signed-off-by) in the patch ). There should be a smarter way.
In. under the GIT/rebase-apply directory, the corresponding patch file is stored, and the name is "0001" (in the updated git version, the directory name for storing the patch file has changed, the GIT version used here is 1.7.4.1 ).
In fact, you can use the GIT apply command to create a patch (GIT apply is the patch command in GIT ). As with the patch-P1 command, and then manually resolve the code conflict (view the generated. rej file, compared with the conflicting file, modify the conflicting content, and finally add the file to the index ):
$ Git apply patch -- reject $ Edit Edit Manually resolve all conflicts according to the. rej file) $ Git add fixed_files $ Git am -- resolved
That's easy! I want to explain more. Git am does not change the index. You need to use git apply -- reject to create a patch (saved in. git/rebase-apply) to manually resolve code conflicts) add to (GIT add) index, and finally tell git am that you have solved (-- resolved) the problem. The advantage is that you do not need to re-edit the commit information. Besides, if you are playing a series of patches (that is, you are playing multiple patches, for example
Git am *. Patch) You do not need to use git am -- abort, and then git AM.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.