[PATCH 0 of 2] Cherry picking with rebase

Matt Mackall mpm at selenic.com
Tue Mar 31 14:39:17 CDT 2009


On Sun, 2009-03-29 at 22:28 +0200, Stefano Tortarolo wrote:
> These patches allows to rebase just some revisions of a branch.
> e.g. rebase -s x --upto x+3 -d y
> 
> It's important to notice that rebasing an intermediate
> revision implies rebasing also their parents up to its base.

Yeah. That's not what's wanted here. If I have:

a-b-c-d-e
   \
    f

I sometimes want to copy just change d onto the f branch. That's
cherry-picking. Change c may be an unrelated change that I don't want.
It's easy to define this in terms of diff() and patch() primitives:

patch(f, diff(c, d))

It's less clear how we'd define this with merge rather than diff and
patch. But backout might provide a hint. If we have:

a-b-c-d-e

and we want to take out change d, we do something like this:

a-b-c-d-e-f
       \ /
        c'  <- undo change d 

So in our original example:

a-b-c-d-e
   \
    f

We've first got to make a new branch that has just the change we want on
it relative to b:

a-b-c--d-e
     \  \
      b'-d'

Now we can merge d' with f and get d'', which is our cherry-picked
patch:

a-b-c-b'-d'
   \      \
    f------d''

All we need for this is revert and merge operations. Also note that we
can revert a whole range of changes between b and d in one step, if
needed.

We can probably also think of this as a pair of rebase-like operations.
One to transplant d onto the common ancestor b, then one to move it onto
the branch.

-- 
http://selenic.com : development and support for Mercurial and Linux




More information about the Mercurial-devel mailing list