Problem: how move a branch back to a previous revision?

Kurt Granroth kurt.mercurial at granroth.com
Sun May 16 17:02:31 UTC 2010


On 5/16/10 5:55 AM, Bram Moolenaar wrote:
> Kurt Granroth wrote:>
>> I am curious why you wanted to perform a rebase in the first place.
>>   From the sounds of it, you received the patch on the default branch for
>> version 7.2.432 and you *also* wanted the same patch on the unstable
>> vim73 branch.  Getting patches from the stable branch to the dev branch
>> sounds like a canonical case of using a merge, to me.  So why rebase and
>> not merge?
>
> That's what I am doing now, since rebase screwed it up once I'm avoiding
> it.
>
> Merge works, but it's not nice.  The merged patch gets into the unstable
> branch at an arbitrary point.  It's much better if it works like the
> unstable branch starts at the last change in the stable branch.
> That's the whole point of "rebase", isn't it?
>
> I'm surprised there is no "hg patch" command.  So I need to do "hg
> export" in the stable branch first, then "hg import" in the unstable
> branch.  Well, it does give me a chance to edit the patch to remove the
> update to the list of patch numbers, that part would fail to apply.  And
> then the changed patch is accepted as if it wasn't edited...

Think of 'rebase' as 'hg move-patch' (or similar).  It rewrites the 
changeset history to move patches around inside of the history.  You 
*could* rebase the stable patch to the beginning of the unstable branch 
(and preserve the branch name with --keepbranches) but that has some 
inherent problems.

First, rebase only works if you've never pushed any of the changes that 
you are rebasing.  As soon as somebody else has pulled your changes, 
your rebase is no longer moving the patch -- it's creating duplicates of 
everything.

Second, what if you have another stable patch later on?  Do you move it 
to the beginning of the dev branch as well?  If so, you will surely have 
pushed your changes since then and you're right back into the "never 
rebase after a push" territory.

Mercurial's history is strictly sequential so the idea of inserting 
patches into arbitrary spots in the history runs counter to Mercuria's 
very core.  Commands like rebase and mq and histedit and the like can 
all be used to edit history as niche cases... but ONLY if your changes 
are strictly local and have never been shared!

Your point about an 'hg patch' is a good one.  Say you want the stable 
patch copied over to your dev branch with the same author and same 
comment and everything.  'hg merge' doesn't do that.  Off the top of my 
head, I can't think of an easy way to do that without using 
export/import.  Hrm.

Kurt

P.S., Thanks for vim!  I've used vim as my primary editor since back in 
the days when vim and elvis duked it out for standard-vi-replacement 
status on early Linux systems (circa 1993 or so)



More information about the Mercurial mailing list