Subject: Re: [PATCH] rebase [--onto O] A B: omit needless checkout

From: Johannes Sixt <[email-masked]>
Date: Wed, 19 Mar 2008 13:54:37 +0100

Junio C Hamano schrieb:
> This teaches "git rebase [--onto O] A B" to omit an unnecessary checkout
> of branch B before it goes on.
> 
> "git-rebase" originally was about rebasing the current branch to somewhere
> else, and when the extra parameter to name which branch to rebase was
> added, it defined the semantics to the safest but stupid "first switch to
> the named branch and then operate exactly the same way as if we were
> already on that branch".
> 
> But the first thing the real part of "rebase" does is to reset the work
> tree and the index to the "onto" commit.  Which means the "rebase that
> branch" form switched the work tree to the tip of the branch only to
> immediately switch again to another commit.  This was wasteful.

This works for a frequent use-case of mine:

  $ git rebase master devel

where I am already on branch master, and now want to rebase devel on top
of it.

The code seems to take care of a lot of corner cases and less frequent
use-cases, including using --onto, which I don't feel able to judge about.

> +# git reset --hard "$onto^0"

Don't forget to remove this line. ;)

-- Hannes