rebase to ancestor: just do it

Martin Geisler mg at aragost.com
Mon Sep 12 10:52:14 CDT 2011


Arne Babenhauserheide <arne_bab at web.de> writes:

> Am Montag, 12. September 2011, 15:01:55 schrieb Martin Geisler:
>> Merging with an ancestor makes little sense. Imagine we merge [a]
>> with [x] in
>> 
>>   ... [a] --- [b] --- [x]
>> 
>> to get
>> 
>>   ... [a] --- [b] --- [x]
>>          \               \
>>           `-------------- [x']
>> 
>> Here [x'] == [x] by the normal rules for how three-way merges work.
>> So the rebase is more a collapse in this case -- not what we want.
>
> Actually [x'] should be [x] with [b] backed out, so we can merge [b]
> into it.
>
> [x'] = [x-b]

Yes and in general we can transform

  ... [A0] --- [B0] --- [B1] ... [Bm] --- [A1] --- [A2] ... [An]

into

  ... [A0] --- [B0] --- [B1] ... [Bm]
          \
           [A1'] --- [A2'] ... [An']

by first creating

  ... [A0] --- [B0] --- [B1] ... [Bm] --- [A1] --- [A2] ... [An]
                                     \
                                      [A0']

where [A0'] has the same file content at [A0], and then rebasing A1...An
onto A0':

  ... [A0] --- [B0] --- [B1] ... [Bm]
                                     \
                                      [A0'] --- [A1'] --- [A2'] ... [An']

Since [A0] and [A0'] are identical, we can change the ancestor of [A1']
to [A0] and get the same diff in [A1'] (this changes the hash again):

  ... [A0] --- [B0] --- [B1] ... [Bm]
          \
           [A1''] --- [A2''] ... [An'']

In Mercurial pseudo-command terms this would be

  hg update Bm
  hg revert --all --rev A0
  hg commit -m "A0'"
  hg rebase --base An
  hg export A1' A2' ... An'
  hg update A0
  hg import A1' A2' ... An'
  hg strip A0'

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://mercurial.aragost.com/kick-start/


More information about the Mercurial mailing list