git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@raisama.net>
To: git@vger.kernel.org
Subject: Bug: 'git am --abort' can silently reset the wrong branch
Date: Wed, 6 May 2009 16:19:46 -0300	[thread overview]
Message-ID: <20090506191945.GG6325@blackpad> (raw)

Hi,

I've ben bitten by this multiple times, while maintaining a multi-branch
repository. 'git am --abort' can drop the whole history of a branch, if you
switch branches before running it. Below are the steps to reproduce the
problem:

[foo/branch1]$ git --version
git version 1.6.3.rc4.29.g8146

I have two branches, with distinct changes:

[foo/branch1]$ git diff branch1 branch2
diff --git a/file.txt b/file.txt
index e8a7b03..a11bf50 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
 initial content
-branch1 content, version 1
+branch2 content. lots of changes here. version 12345.
[foo/branch1]$ git status
# On branch branch1
nothing to commit (working directory clean)
[foo/branch1]$


I receive a patch and try to apply it to branch1:

[foo/branch1]$ git am /tmp/patch.patch
Applying: patch to be applied
fatal: corrupt patch at line 13
Patch failed at 0001 patch to be applied
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
[foo/branch1]$

(Seeing that solving this conflict will take some time. I go out to grab some
coffee).

(When back to work, somebody asks me to take a look on patch2.patch, that
applies to branch2).

[foo/branch1]$ git checkout branch2
Switched to branch 'branch2'
[foo/branch2]$ git am /tmp/patch2.patch
previous rebase directory /tmp/foo/.git/rebase-apply still exists but mbox given.
[foo/branch2]$


(Oh, I see. There was a pending 'git am' operation. Let's just cancel it, I can
start it again later anyway).

Here is where "git am" silently does the wrong thing:

[foo/branch2]$ git am --abort
[foo/branch2]$ cat file.txt
initial content
branch1 content, version 1
[foo/branch2]$

(Hey! where are the changes from branch2?)

[foo/branch2]$ git diff branch1 branch2
[foo/branch2]$

Ouch.   :(


When that happens, I need to resort to git reflog, and manually git-reset
branch2 to point to the original commit.

I don't know what would be the best approach to avoid this issue. I tested a
similar scenario using 'git rebase' and 'git rebase --abort' switched back to
branch1 before resetting the branch state, instead of resetting branch2. Maybe
'git am' could do the same.

-- 
Eduardo

             reply	other threads:[~2009-05-06 19:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-06 19:19 Eduardo Habkost [this message]
2009-05-08  8:28 ` Bug: 'git am --abort' can silently reset the wrong branch Jeff King
2009-05-08  8:37   ` Sverre Rabbelier
2009-05-08  9:01   ` Junio C Hamano
2009-05-08  9:12     ` Jeff King
2009-05-25 10:43       ` [RFC PATCH] am: do not do any reset on --abort Jeff King
2009-05-25 11:49         ` Johannes Schindelin
2009-05-25 12:00           ` Jeff King
2009-05-25 12:17             ` Johannes Sixt
2009-05-25 15:54               ` Avery Pennarun
2009-05-25 16:00                 ` Jeff King
2009-05-25 16:02               ` Jeff King
2009-05-25 16:10                 ` Avery Pennarun
2009-05-25 22:23         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090506191945.GG6325@blackpad \
    --to=ehabkost@raisama.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).