Zwillingssterns Weltenwald
Published on Zwillingssterns Weltenwald (http://www.zwillingsstern.de)

Startseite > Renaming a Mercurial branch with the evolve extension

Renaming a Mercurial branch with the evolve extension

Short version (rename from $OLD to $NEW):

ROOT="$(hg id -qr 'first(roots(branch('$OLD')))')"
MSG="$(hg log -r $ROOT -T '{desc}')"  

hg update $ROOT
hg branch $NEW
hg commit --amend -m "$MSG"
hg evolve --all

Mercurial records in which named branch a commit was created. This can be inconvenient when you choose temporary branch names like "foo" or "justworkdamnit".

The evolve extension [1] enables safe, collaborative history editing which removes this inconvenience while preserving the reliability guarantees of Mercurial [2].

Here I show in a quick example how to rename a branch in Mercurial using the evolve extension.

You can use this method for all changes which you did not transfer elsewhere yet (they must be in draft or secret phase [3]).

Note (2016): The evolve extension is still in testing. Do not use it for production yet. If you want to help stabilizing it, please join evolve-testers [4]. I’ve been using it for more than a year, but I know how to fix things when I hit a bug in the evolve extension.

Setup evolve

hg clone https://www.mercurial-scm.org/repo/evolve/ ~/.local/share/hgext-evolve
echo "[extensions]
evolve = ~/.local/share/hgext-evolve/hgext/evolve.py" >> ~/.hgrc

Rename a branch

create repo with wrong branch name

hg init foo
cd foo
echo 1 > 1
hg ci -Am 1
echo stable > 1
hg branch stapling
hg ci -m stable
# add a second commit to the branch
# to make this non-trivial
echo stable2 > 1
hg ci -m stable2

change the branch name

# amend the first revision in the branch
hg up -r "first(branch(stapling))"
hg branch stable
hg ci --amend -m stable
# (notes that there is an unstable changeset)
# evolve the history
hg evolve

and check that it’s correct

hg log -G

That’s it.

Result

@  changeset:   5:1822f3b02b72
|  branch:      stable
|  tag:         tip
|  user:        Freenet
|  date:        Fri Nov 18 00:56:57 2016 +0100
|  summary:     stable2
|
o  changeset:   4:d47764612e1a
|  branch:      stable
|  parent:      0:d2b5bb69b11b
|  user:        Freenet
|  date:        Fri Nov 18 00:56:56 2016 +0100
|  summary:     stable
|
o  changeset:   0:d2b5bb69b11b
   user:        Freenet
   date:        Fri Nov 18 00:56:55 2016 +0100
   summary:     1

☺ Yay! ☺

Happy Hacking!

PS: If you want to share this: Short on GNU social [5]

PPS: If you want to tweet this:

hg branch name O→N
I="$(hg id -qr 'first(branch('$O'))')"
M="$(hg log -r $I [6] -T' {desc}')"
hg up $I [6]
hg branch $N [7]
hg ci --amend -m "$M"
hg ev

— ((λ()'ArneBab)) (@ArneBab) November 18, 2016 [8]

PPPS: For efficient collaboration via Mercurial see the complete branching strategy [9].

Werke von Arne Babenhauserheide. Lizensiert, wo nichts anderes steht, unter der GPLv3 or later und weiteren freien Lizenzen.

Diese Seite nutzt Cookies. Und Bilder. Manchmal auch Text. Eins davon muss ich wohl erwähnen — sagen die meisten anderen, und ich habe grade keine Zeit, Rechtstexte dazu zu lesen…


Source URL: http://www.zwillingsstern.de/english/mercurial/rename-branch-evolve

Links:
[1] https://www.mercurial-scm.org/wiki/EvolveExtension
[2] https://www.mercurial-scm.org
[3] https://www.mercurial-scm.org/wiki/Phases
[4] https://www.mercurial-scm.org/mailman/listinfo/evolve-testers
[5] http://sn.1w6.org/conversation/163665#notice-191445
[6] https://twitter.com/search?q=%24I&src=ctag
[7] https://twitter.com/search?q=%24N&src=ctag
[8] https://twitter.com/ArneBab/status/799607154739126272
[9] http://www.draketo.de/branching-strategy