91

I'm trying to apply a patch, which I took from http://www.winehq.org/pipermail/wine-devel/2014-May/104356.html. I copied it into a text editor, and saved it as my.patch (I needed to fix the email, it had been obfuscated).

I tried to apply it with Git, but I'm getting this error:

sashoalm@sashoalm-VirtualBox:~/Desktop/wine-git$ git am --signoff <my.patch
previous rebase directory /home/sashoalm/Desktop/wine-git/.git/rebase-apply still exists but mbox given.

This cryptic error message gives me no idea what's wrong or what I need to do to make it work. What does this error mean? And how do I fix it?

sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

101
git am --abort

worked for me, but git rebase --abort did not.

What happened: I tried to apply a patch but it had been corrupted (likely by Gmail copy pasting in body):

git am bad.patch

And Git said:

Applying: python: fix Linetable case to LineTable in docstrings and comments
fatal: corrupt patch at line 56
Patch failed at 0001 python: fix Linetable case to LineTable in docstrings and comments
The copy of the patch that failed is found in:
   /home/ciro/git/binutils-gdb/src/.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".

Note how git gives out the solution: To restore the original branch and stop patching, run "git am --abort".

Then I obviously ignored the message, and tried a fixed version immediately:

git am good.patch

and got the error.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • While this is correct, I find this answer unclear, and I had to read the comments on [sashoalm's answer](https://stackoverflow.com/a/24121809/3982001) to fully understand what happened. In short, the problem is that after `git am bad.patch` failed, you tried to apply the good patch before cleaning up, and this is what caused the puzzling `still exists but mbox given` error. The solution: when `git am` fails, you can't just apply another patch, you must first clean up the mess, for example with `git am --abort` (or whatever `git status` suggests). – Fabio says Reinstate Monica Jul 04 '22 at 13:45
  • The part that confused me the most is "Then I *obviously* ignored the message": "obviously" seems to suggest that it is the solution, whereas you were just being ironic about not paying attention to error messages. Another confusing thing is that there are two errors here (the bad patch, and the `mbox given` message), and applying the good patch solves the first one, but the question is about the second one. – Fabio says Reinstate Monica Jul 04 '22 at 13:54
42

Ok, it turned out I needed to delete the directory .git/rebase-apply. It works after that (or at least gives me different errors, saying the email is wrong again). I still have no idea what the error actually means or why there was an error.

Edit: As the comments below suggest, git am --abort or git rebase --abort might be a better way to fix the problem, but I have not tested it.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • 2
    The error means that at some point you ran a `git rebase` that stopped due to some conflict and was waiting for you to complete some actions and do `git rebase --continue` to finish up. The proper way to resolve that situation is either a) fix what `git rebase` was having issues with and then `git rebase --continue`, or b) `git rebase --abort`. Your repository may or may not be confused now. Read `git help rebase` for more information. – twalberg Jun 12 '14 at 14:15
  • The "rebase" was being caused by `git apply` or `git am`. After they failed (because of the incorrect email), they created this directory. I had no reason to think that git considers applying a patch to be in fact a rebase. – sashoalm Jun 12 '14 at 15:30
  • 11
    +1 for suggesting `git rebase --abort` that would have fixed my problems. If the issue was caused by a bad merge, `git am --abort` may be the way to go. – Barton Chittenden Jul 02 '14 at 19:53
  • 5
    The issue in my case is it said `git rebase --abort` wouldn't work bc git am was already running. I think either you'll need to get rid of the dir as you suggested or run `git am --abort`. – Kevin Ghadyani Jan 06 '15 at 22:17
  • 3
    this may happen for other commands. so instead of blindly copying commands, run `git status` and the first few lines will tell you if there is a rebase/am/etc in progress and what are your options. – gcb Jan 12 '15 at 00:35