Thursday, January 21, 2010

Applying a patch with "git am"

I decided to write this because I hate losing hours in a trivial work and found no information to be supported on.

The git tutorial states:

================================================================================================
Importing patches to a project

Git also provides a tool called git-am(1) (am stands for "apply mailbox"), for importing such an emailed series of patches. Just save all of the patch-containing messages, in order, into a single mailbox file, say "patches.mbox", then run

$ git am -3 patches.mbox

Git will apply each patch in order; if any conflicts are found, it will stop, and you can fix the conflicts as described in "Resolving a merge". (The "-3" option tells git to perform a merge; if you would prefer it just to abort and leave your tree and index untouched, you may omit that option.)

Once the index is updated with the results of the conflict resolution, instead of creating a new commit, just run

$ git am --resolved

and git will create the commit for you and continue applying the remaining patches from the mailbox.
================================================================================================

But... what will happened if you get the message:

Failed to merge in the changes.
Patch failed at 0001 Implementacion de excepciones en SOA SaveEntities
When you have resolved this problem run "git am -3 --resolved".
If you would prefer to skip this patch, instead run "git am -3 --skip".
To restore the original branch and stop patching run "git am -3 --abort".

Ok, I lost 3 hours of my beloved time trying to solve this problem, everytime I did the "git mergetool" and solved the problem the command "git am -3 --resolved" show me this:

Applying: Implementacion de excepciones en SOA SaveEntities
No changes - did you forget to use 'git add'?

I was like... WTF? I tried to do a "git status" and nothing was in "unstaged" mode, I tried to add the damn file, and nothing... --abort, reset --hard... all the process again and... nothing!

That was frustrating, but I finally found a solution for this... the problem was with the "git mergetool", this tool does an "Autocommit" and, I don't know why, this does not include the automerged file, what I did?

git am --3way PATHFILE
solve the problem manually with gedit (any editor will do the trick)
git add the fixed files
git am --resolved

and that worked.

I hope this could save some hours to someone else... if it does, let me know... it's highly appreciated when you know that you didn't lose your time writing stuff and nobody read it xD

No comments:

Post a Comment