Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in running 'git apply'

Tags:

git

Can you please tell me how can I resolve the 'patch does not apply' error when I try to 'git apply-patch'?

$ git apply 0001-my.patch
error: patch failed:test.xml:114
error: text.xml: patch does not apply

I do have 'test.xml' in my local directory. And when I do 'git status', it shows I don't have local changes.

Thank you for any help.

like image 399
hap497 Avatar asked Dec 03 '09 21:12

hap497


2 Answers

You can try a:

git am -3

When the patch does not apply cleanly, fall back on 3-way merge (git am doc)


qneill mentions in the comments that git apply now have a --3way option:

you can now apply your patches without having to reduce context.
As it will leave the conflicted halves in the index and let you manually resolve conflicts in the working tree, "--3way" implies "--index", and cannot be used with "--cached" or "--reject".

You can see it in the git1.7.12 release note (August 2012, a bit less than 3 years after the original question)

"git apply" learned to wiggle the base version and perform three-way merge when a patch does not exactly apply to the version you have.

like image 75
VonC Avatar answered Oct 31 '22 00:10

VonC


Well, the patch has information about what should be change to what. If the first what doesn't match file contents, the patch doesn't apply.

like image 30
Michael Krelin - hacker Avatar answered Oct 30 '22 22:10

Michael Krelin - hacker