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 enables safe, collaborative history editing which removes this inconvenience while preserving the reliability guarantees of Mercurial.

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).

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. 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 ~/.local/share/hgext-evolve
echo "[extensions]
evolve = ~/.local/share/hgext-evolve/hgext/" >> ~/.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.


@  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

PPS: If you want to tweet this:

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

Inhalt abgleichen
Willkommen im Weltenwald!

Beliebte Inhalte news

Draketo neu: Beiträge