git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFD] make rebase abort to original branch, not rebased branch
@ 2011-03-13  3:58 Martin von Zweigbergk
  2011-03-13  7:05 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Martin von Zweigbergk @ 2011-03-13  3:58 UTC (permalink / raw)
  To: git

When git rebase is aborted, it will return the HEAD to the rebased
branch (which has not moved). If the current branch is "topic" and a
run of "git rebase master" is aborted, "topic" is therefore checked
out, which is both what I expect and what I want. When the
two-argument version of git rebase is used, as in "git rebase master
topic", and then aborted, "topic" will be checked out. This is not
what I would expect, although I'm aware of it by now, and usually not
what I want. I would expect to be returned to the branch/commit that
was checked out when I started "git rebase master topic".

In most cases, this is just a small annoyance, since it's usually
quick and easy to manually switch back to the original
branch. However, I have run into at least two cases where it has been
a bit more annoying:

 1. When on a detached HEAD and running "git rebase HEAD topic", if
    you abort the rebase, you will have to look up the old commit in
    the reflog.

 2. I once was rebasing many old branches, mostly to see which ones
    could be rebased without conflicts. The project I was working on
    was pretty big and a lot had changed since those old branches were
    created. If a "new" branch is currently checked out and "git
    rebase master old-branch" is run and causes conflicts, the old
    branch would be checked out. In my case, this would take 5-10
    seconds. Since Junio improved rebase in 0cb0664 (rebase [--onto O]
    A B: omit needless checkout, 2008-03-15), there will be no
    checkouts of any "old" commit in the successful case, so it's a
    shame that it has to happen in the unsuccessful case when the
    rebase is aborted.

Are there valid cases where the current behavior is bettter?

I suppose we can not just change the current behavior due to backward
compatibility constraints. We could introduce a configuration
variable, of we could perhaps change it in 1.8.0. Maybe the problem is
not big enough to do either...


/Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFD] make rebase abort to original branch, not rebased branch
  2011-03-13  3:58 [RFD] make rebase abort to original branch, not rebased branch Martin von Zweigbergk
@ 2011-03-13  7:05 ` Junio C Hamano
  2011-03-13  7:46   ` Junio C Hamano
  2011-03-13 14:58   ` Martin von Zweigbergk
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2011-03-13  7:05 UTC (permalink / raw)
  To: Martin von Zweigbergk; +Cc: git

Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:

> In most cases, this is just a small annoyance, since it's usually
> quick and easy to manually switch back to the original
> branch. However, I have run into at least two cases where it has been
> a bit more annoying:
>
>  1. When on a detached HEAD and running "git rebase HEAD topic", if
>     you abort the rebase, you will have to look up the old commit in
>     the reflog.

Doesn't this merely show a bad discipline? What were you envisioning to
do to your detached HEAD state if the rebase were to succeed? IOW, if the
state was so precious, why did you decide to switch to topic and rebase it
onto that state, without marking?

> Are there valid cases where the current behavior is bettter?

I don't particularly like the "when aborted it returns to the original
location" behaviour even for a single argument "git rebase A" case (I do
deeply care about the tip of the branch that you attempted to rebase _is_
set back to the original state, but I don't care deeply on which branch
you would end up on myself), but because "git rebase A B" is a shorthand
for "git checkout B; git rebase A" (at least that is how I view it
myself), I would imagine that it would be more surprising to switch back
to the branch you were on which may not have anything to do with A nor B.

At least going back to B conceptually makes more sense in one use case I
have, which was the original reason I invented rebase with the "checkout B
and rebase it ono A" shorthand in the first place (see 59e6b23), back when
I was an active contributor throwing patches at Linus (note that back then
I didn't have "abort then go back" in the code--and that is why I don't
care too deeply about this "which branch should I be after aborting?"
myself).

The reason I tried to rebase B on A with the short-hand form was because I
wanted to clean up what is on B; I may say "abort" when my first attempt
to rebase failed because it was a bit too much to bite at once (e.g. the
history diverged a bit too much since B forked from A's ancestor).

But then, the next thing I would want to do in such a case after aborting
is not to give up and forget about what I needed to do, which is to clean
up B into a shape easier to merge with the updated codebase that leads to
A.  I would want to stay on B and examine the situation a bit deeper, and
try to figuire out a different base (e.g. a bit older commit in the
history leading to A) to rebase to, so that I can keep up with the other
branch incrementally without lagging too far behind.  Switching away from
the original B would be majorly annoying in such a case.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFD] make rebase abort to original branch, not rebased branch
  2011-03-13  7:05 ` Junio C Hamano
@ 2011-03-13  7:46   ` Junio C Hamano
  2011-03-13 14:58   ` Martin von Zweigbergk
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2011-03-13  7:46 UTC (permalink / raw)
  To: Martin von Zweigbergk; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

>> Are there valid cases where the current behavior is bettter?
> ...
> I don't particularly like the "when aborted it returns to the original
> location" behaviour even for a single argument "git rebase A" case (I do
> deeply care about the tip of the branch that you attempted to rebase _is_
> set back to the original state, but I don't care deeply on which branch
> you would end up on myself), but because "git rebase A B" is a shorthand
> for "git checkout B; git rebase A" (at least that is how I view it
> myself), I would imagine that it would be more surprising to switch back
> to the branch you were on which may not have anything to do with A nor B.
>
> At least going back to B conceptually makes more sense in one use case I
> have, which was the original reason I invented rebase with the "checkout B
> and rebase it ono A" shorthand in the first place (see 59e6b23), back when
> I was an active contributor throwing patches at Linus (note that back then
> I didn't have "abort then go back" in the code--and that is why I don't
> care too deeply about this "which branch should I be after aborting?"
> myself).
> ...

Having said all that, my opinion would be very different if the definition
of "git rebase A B" were different.  I can imagine that some people may be
tempted to (mis)understand the form of the command as a way to "rebase B
on top of A, even though I am doing something unrelated to B (my work may
or may not be related to A), because I need to help somebody who wants to
have an access to an updated B _now_, and I'll continue what I am doing
(which is not related to B) after I am done rebasing".

Actually, I would not say that such a workflow is unreasonable.

And for people who want such a workflow out of "rebase A B", it would be a
bug that the command does not to come back to your original branch when it
finishes rebasing B on top of A, and it would equally be a bug when it
stops with a conflict and you tell it to abort. In _both_ cases, you would
want to come back to the branch you started from.

But "git rebase A B" after successful completion does not come back to
your original branch (it stays on B), because the current semantics of the
command is not about supporting such a workflow.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFD] make rebase abort to original branch, not rebased branch
  2011-03-13  7:05 ` Junio C Hamano
  2011-03-13  7:46   ` Junio C Hamano
@ 2011-03-13 14:58   ` Martin von Zweigbergk
  2011-03-13 15:27     ` Alexander Miseler
  1 sibling, 1 reply; 5+ messages in thread
From: Martin von Zweigbergk @ 2011-03-13 14:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Martin von Zweigbergk, git

On Sat, 12 Mar 2011, Junio C Hamano wrote:

> Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
> 
> > In most cases, this is just a small annoyance, since it's usually
> > quick and easy to manually switch back to the original
> > branch. However, I have run into at least two cases where it has been
> > a bit more annoying:
> >
> >  1. When on a detached HEAD and running "git rebase HEAD topic", if
> >     you abort the rebase, you will have to look up the old commit in
> >     the reflog.
> 
> Doesn't this merely show a bad discipline? What were you envisioning to
> do to your detached HEAD state if the rebase were to succeed? IOW, if the
> state was so precious, why did you decide to switch to topic and rebase it
> onto that state, without marking?

This usually happens when I see something that looks a bit suspicious
in one of my own commits on my topic branch. I then check out that
commit to have a look and perhaps run some test. If I find something
broken, I would fix it and either amend the commit or create a new
commit on top. I would then run "git rebase --onto HEAD HEAD~1 topic"
or "git rebase HEAD topic", respectively. If the merge conflicts turn
out to be bigger than I expected, I may decide to abort and to instead
create a new branch for the commit(s) until I find time/energy.

> > Are there valid cases where the current behavior is bettter?
> 
> I don't particularly like the "when aborted it returns to the original
> location" behaviour even for a single argument "git rebase A" case

This has sometimes annoyed me as well. Maybe a --stop/discard would be
a nice alternative to "rf -r .git/(rebase-apply|rebase-merge)"?

> At least going back to B conceptually makes more sense in one use case I
> have, which was the original reason I invented rebase with the "checkout B
> and rebase it ono A" shorthand in the first place (see 59e6b23), back when
> I was an active contributor throwing patches at Linus (note that back then
> I didn't have "abort then go back" in the code--and that is why I don't
> care too deeply about this "which branch should I be after aborting?"
> myself).
> 
> The reason I tried to rebase B on A with the short-hand form was because I
> wanted to clean up what is on B; I may say "abort" when my first attempt
> to rebase failed because it was a bit too much to bite at once (e.g. the
> history diverged a bit too much since B forked from A's ancestor).
> 
> But then, the next thing I would want to do in such a case after aborting
> is not to give up and forget about what I needed to do, which is to clean
> up B into a shape easier to merge with the updated codebase that leads to
> A.  I would want to stay on B and examine the situation a bit deeper, and
> try to figuire out a different base (e.g. a bit older commit in the
> history leading to A) to rebase to, so that I can keep up with the other
> branch incrementally without lagging too far behind.  Switching away from
> the original B would be majorly annoying in such a case.

Certainly a valid use case. Maybe the best solution would be to
introduce a new kind of --abort (say --abort-to-branch-before-rebase,
but with a better name)?


/Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFD] make rebase abort to original branch, not rebased branch
  2011-03-13 14:58   ` Martin von Zweigbergk
@ 2011-03-13 15:27     ` Alexander Miseler
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Miseler @ 2011-03-13 15:27 UTC (permalink / raw)
  To: Martin von Zweigbergk; +Cc: Junio C Hamano, git

>>> In most cases, this is just a small annoyance, since it's usually
>>> quick and easy to manually switch back to the original
>>> branch. However, I have run into at least two cases where it has been
>>> a bit more annoying:
>>>
>>>  1. When on a detached HEAD and running "git rebase HEAD topic", if
>>>     you abort the rebase, you will have to look up the old commit in
>>>     the reflog.
>>
>> Doesn't this merely show a bad discipline? What were you envisioning to
>> do to your detached HEAD state if the rebase were to succeed? IOW, if the
>> state was so precious, why did you decide to switch to topic and rebase it
>> onto that state, without marking?
> 
> This usually happens when I see something that looks a bit suspicious
> in one of my own commits on my topic branch. I then check out that
> commit to have a look and perhaps run some test. If I find something
> broken, I would fix it and either amend the commit or create a new
> commit on top. I would then run "git rebase --onto HEAD HEAD~1 topic"
> or "git rebase HEAD topic", respectively. If the merge conflicts turn
> out to be bigger than I expected, I may decide to abort and to instead
> create a new branch for the commit(s) until I find time/energy.

This can be easily fixed for your own repository by installing a pre-rebase hook that force-sets a temporary branch (named e.g. "pre-rebase") to the current commit before starting the rebase. I can highly recommend having such a hook, it's damn useful.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-03-13 15:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-13  3:58 [RFD] make rebase abort to original branch, not rebased branch Martin von Zweigbergk
2011-03-13  7:05 ` Junio C Hamano
2011-03-13  7:46   ` Junio C Hamano
2011-03-13 14:58   ` Martin von Zweigbergk
2011-03-13 15:27     ` Alexander Miseler

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).