# rebase vs rebase -i

10 messages from 2010-02-04 to 2010-02-05. Participants: Jay Soffian, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/22515

## Jay Soffian, 2010-02-04 04:19

Subject: rebase vs rebase -i
Message-ID: <76718491002032019i5f8ea947paa527988ddb7a378@mail.gmail.com>
URL: https://gitlist.dev/e/76718491002032019i5f8ea947paa527988ddb7a378%40mail.gmail.com

```
Why does git rebase use format-patch + am, while rebase -i uses cherry-pick?

Just curious. In particular though, it seems especially odd in this case:

$ git rebase --onto <newbase> <upstream>

vs

$ env GIT_EDITOR=true git rebase -i --onto <newbase> <upstream>

Both in theory produce an identical end-result, while using two
different implementations.

(Here I'm setting GIT_EDITOR=true just to demonstrate that I didn't
change the list of commits in the latter case.)

j.

```

## Johannes Schindelin, 2010-02-04 13:27

Subject: Re: rebase vs rebase -i
Message-ID: <alpine.DEB.1.00.1002041414530.4505@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.1002041414530.4505%40intel-tinevez-2-302
In-Reply-To: <76718491002032019i5f8ea947paa527988ddb7a378@mail.gmail.com>

```
Hi,

On Wed, 3 Feb 2010, Jay Soffian wrote:

> Why does git rebase use format-patch + am, while rebase -i uses 
> cherry-pick?

Hysterical raisins. 'rebase -i' started out as 'edit-patch-series.sh', 
hacked together in 4 hours on a lazy Saturday afternoon:
http://colabti.org/irclogger/irclogger_log/git?date=2007-02-27#l97

Ah, the old days. Back when I had enough time to read through Peff's 
mails. And back when I had enough time to cobble together fun Git scripts.

> Just curious. In particular though, it seems especially odd in this 
> case:
> 
> $ git rebase --onto <newbase> <upstream>
> 
> vs
> 
> $ env GIT_EDITOR=true git rebase -i --onto <newbase> <upstream>
> 
> Both in theory produce an identical end-result, while using two
> different implementations.
> 
> (Here I'm setting GIT_EDITOR=true just to demonstrate that I didn't
> change the list of commits in the latter case.)

You can get _exactly_ the same behavior if you use -m.

Ciao,
Dscho

```

## Jay Soffian, 2010-02-04 17:14

Subject: Re: rebase vs rebase -i
Message-ID: <76718491002040914t12956bb2gbe21ae89f31cbc7f@mail.gmail.com>
URL: https://gitlist.dev/e/76718491002040914t12956bb2gbe21ae89f31cbc7f%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.1002041414530.4505@intel-tinevez-2-302>

```
On Thu, Feb 4, 2010 at 8:27 AM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>> (Here I'm setting GIT_EDITOR=true just to demonstrate that I didn't
>> change the list of commits in the latter case.)
>
> You can get _exactly_ the same behavior if you use -m.

Or rather, -p. ;-)

j.

```

## Johannes Schindelin, 2010-02-04 18:00

Subject: Re: rebase vs rebase -i
Message-ID: <alpine.DEB.1.00.1002041859000.4505@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.1002041859000.4505%40intel-tinevez-2-302
In-Reply-To: <76718491002040914t12956bb2gbe21ae89f31cbc7f@mail.gmail.com>

```
Hi,

On Thu, 4 Feb 2010, Jay Soffian wrote:

> On Thu, Feb 4, 2010 at 8:27 AM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> >> (Here I'm setting GIT_EDITOR=true just to demonstrate that I didn't
> >> change the list of commits in the latter case.)
> >
> > You can get _exactly_ the same behavior if you use -m.
> 
> Or rather, -p. ;-)

No.  -p tries to preserve merges, and it will use 
git-rebase--interactive.sh for hysterical raisins.

I meant -m.

Ciao,
Dscho

```

## Jay Soffian, 2010-02-04 18:10

Subject: Re: rebase vs rebase -i
Message-ID: <76718491002041010k84ad55ct5c3e80529e8f8428@mail.gmail.com>
URL: https://gitlist.dev/e/76718491002041010k84ad55ct5c3e80529e8f8428%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.1002041859000.4505@intel-tinevez-2-302>

```
On Thu, Feb 4, 2010 at 1:00 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Hi,
>
> On Thu, 4 Feb 2010, Jay Soffian wrote:
>
>> On Thu, Feb 4, 2010 at 8:27 AM, Johannes Schindelin
>> <Johannes.Schindelin@gmx.de> wrote:
>> >> (Here I'm setting GIT_EDITOR=true just to demonstrate that I didn't
>> >> change the list of commits in the latter case.)
>> >
>> > You can get _exactly_ the same behavior if you use -m.
>>
>> Or rather, -p. ;-)
>
> No.  -p tries to preserve merges, and it will use
> git-rebase--interactive.sh for hysterical raisins.
>
> I meant -m.

I don't understand what you mean by "_exactly_ the same behavior" then.

"GIT_EDITOR=true git rebase -i" and "git rebase -p" both use
git-rebase--interactive.sh, and so are exactly the same behavior.

-m still uses git-rebase.sh, but calls merge instead of format-patch +
am. Perhaps the end-result is the same, but the behavior is different.

I guess I'm being a bit pedantic here, but I'm really just trying to
understand what you mean.

Thanks,

j.

```

## Johannes Schindelin, 2010-02-04 18:46

Subject: Re: rebase vs rebase -i
Message-ID: <alpine.DEB.1.00.1002041946170.4505@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.1002041946170.4505%40intel-tinevez-2-302
In-Reply-To: <76718491002041010k84ad55ct5c3e80529e8f8428@mail.gmail.com>

```
Hi,

On Thu, 4 Feb 2010, Jay Soffian wrote:

> On Thu, Feb 4, 2010 at 1:00 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
>
> > On Thu, 4 Feb 2010, Jay Soffian wrote:
> >
> >> On Thu, Feb 4, 2010 at 8:27 AM, Johannes Schindelin
> >> <Johannes.Schindelin@gmx.de> wrote:
> >> >> (Here I'm setting GIT_EDITOR=true just to demonstrate that I didn't
> >> >> change the list of commits in the latter case.)
> >> >
> >> > You can get _exactly_ the same behavior if you use -m.
> >>
> >> Or rather, -p. ;-)
> >
> > No.  -p tries to preserve merges, and it will use
> > git-rebase--interactive.sh for hysterical raisins.
> >
> > I meant -m.
> 
> I don't understand what you mean by "_exactly_ the same behavior" then.

Both "rebase -i" and "rebase -m" are really a cherry-pick in a loop.

Ciao,
Dscho
```

## Jay Soffian, 2010-02-04 19:57

Subject: Re: rebase vs rebase -i
Message-ID: <76718491002041157o37de139brb7995076274375aa@mail.gmail.com>
URL: https://gitlist.dev/e/76718491002041157o37de139brb7995076274375aa%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.1002041946170.4505@intel-tinevez-2-302>

```
On Thu, Feb 4, 2010 at 1:46 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Both "rebase -i" and "rebase -m" are really a cherry-pick in a loop.

Well then I'm still confused. I see where pick_one() in
git-rebase--interactive.sh is using cherry-pick.

But call_merge() in git-rebase.sh is using git-merge-recursive (absent
specifying another strategy).

?

j.

```

## Junio C Hamano, 2010-02-05 00:45

Subject: Re: rebase vs rebase -i
Message-ID: <7vmxzose72.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vmxzose72.fsf%40alter.siamese.dyndns.org
In-Reply-To: <76718491002041157o37de139brb7995076274375aa@mail.gmail.com>

```
Jay Soffian <jaysoffian@gmail.com> writes:

> On Thu, Feb 4, 2010 at 1:46 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
>> Both "rebase -i" and "rebase -m" are really a cherry-pick in a loop.
>
> Well then I'm still confused. I see where pick_one() in
> git-rebase--interactive.sh is using cherry-pick.
>
> But call_merge() in git-rebase.sh is using git-merge-recursive (absent
> specifying another strategy).
>
> ?

I think Dscho's point is that cherry-pick internally runs the same
merge-recursive.

When you have a change C based on its parent C^ and want to replay that
effect on a (possibly unrelated) commit A, you would run three-way merge,
merging C into A as if C^ is the common ancestor.  The rebase script
cherry-pick, and revert all work with the same principle (for revert
obviously you would swap C and C^---you are applying the effect of going
from C to C^ in that case).

And no, "format-patch --stdout | am -3" pipe in the normal rebase codepath
will stay unless you can produce a benchmark that says the performance of
merge machinery is good enough these days.  Back when "rebase -m" was
introduced, it wasn't.

```

## Junio C Hamano, 2010-02-05 01:18

Subject: Re: rebase vs rebase -i
Message-ID: <7vy6j8pjj8.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vy6j8pjj8.fsf%40alter.siamese.dyndns.org
In-Reply-To: <7vmxzose72.fsf@alter.siamese.dyndns.org>

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

> And no, "format-patch --stdout | am -3" pipe in the normal rebase codepath
> will stay unless you can produce a benchmark that says the performance of
> merge machinery is good enough these days.  Back when "rebase -m" was
> introduced, it wasn't.

Just for fun, I pulled from the kernel tree.  Its tip is at fc76be4 (Merge
master.kernel.org:/home/rmk/linux-2.6-arm, 2010-02-04), which is a merge
of a subsystem tree into the mainline.

I tried to rebase HEAD^2 (i.e. subsystem change) on top of HEAD^1 (the
state Linus merged that subsystem change into).  Either way, the
experiment is to linearlize a side branch that has 16 patches:

The experiment is to take a history of this shape:

  --A-...--N--O--P master^2 = test (subsystem tip)
                  \
             ---X--Y master
          master^1

and turn it into a history of this shape:


  --A-...--N--O--P master^2 = test (subsystem tip)
                  \
             ---X--Y master
                 \
                  A'-B'-...O'-P' (rebased tip)

The tree at rebased tip P' must match the merge Y, of course.

First, to prepare:

    $ git checkout -b test master^2 ;# at the tip of subsystem
    $ git checkout HEAD^0 ;# detach so that I can easily repeat

Best of 5 runs on my box are:

    $ git reset --hard test && time git rebase master^1
    real    0m3.060s
    user    0m1.976s
    sys     0m0.812s

vs

    $ git reset --hard test && time git -m rebase master^1
    real    0m19.060s
    user    0m15.025s
    sys     0m3.564s

The numbers are understandable; the series touches only 12 paths among
31.5k paths, so applying patches has to be faster.

I have a plan to make a merge go faster by using a yet another merge
strategy, but that has been backburnered for now.

```

## Jay Soffian, 2010-02-05 01:20

Subject: Re: rebase vs rebase -i
Message-ID: <76718491002041720y104c0778s8614fea5e9038905@mail.gmail.com>
URL: https://gitlist.dev/e/76718491002041720y104c0778s8614fea5e9038905%40mail.gmail.com
In-Reply-To: <7vmxzose72.fsf@alter.siamese.dyndns.org>

```
On Thu, Feb 4, 2010 at 7:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
> I think Dscho's point is that cherry-pick internally runs the same
> merge-recursive.

Ah hah, that's what I was missing. Thank you.

> When you have a change C based on its parent C^ and want to replay that
> effect on a (possibly unrelated) commit A, you would run three-way merge,
> merging C into A as if C^ is the common ancestor.  The rebase script
> cherry-pick, and revert all work with the same principle (for revert
> obviously you would swap C and C^---you are applying the effect of going
> from C to C^ in that case).
>
> And no, "format-patch --stdout | am -3" pipe in the normal rebase codepath
> will stay unless you can produce a benchmark that says the performance of
> merge machinery is good enough these days.  Back when "rebase -m" was
> introduced, it wasn't.

Indeed, the difference is painful on a largish tree (910M after gc
--aggressive, 39k files). Best of 3 runs for each of these:

$ time git rebase --onto HEAD~11 HEAD~10
First, rewinding head to replay your work on top of it...
[...]
real	0m11.164s
user	0m2.671s
sys	0m4.836s

$ time git rebase -m --onto HEAD~11 HEAD~10
[...]
real	0m40.507s
user	0m17.848s
sys	0m16.052s

$ time GIT_EDITOR="sed -i -e 1d" git rebase -i HEAD~11
[...]
real	0m27.758s
user	0m12.615s
sys	0m13.134s

It looks like there's room for improvement to rebase -m. (2.53 Ghz
Core 2 Duo Macbook Pro, 4GB memory.)

j.

```
