Question

I created a couple of anonymous branches in Mercurial (using TortoiseHg).

But now I regret not naming them, because they're [special] revisions after all.

Is there a way to name these nameless branches?

i.e.: enter image description here

Change the name of 45 and 46 from "default" to something else.

Was it helpful?

Solution 2

You can do this with the hg rebase extension.

Something like this should do it:

hg up 44
hg branch what_I_wish_I_called_45
hg commit
hg rebase --base 45 --dest 47
hg commit
hg up 44
hg branch what_I_wish_I_called_46
hg commit
hg rebase --base 46 --dest 48
hg commit

Explanation:

  • Get revision 44
  • Create a new branch with the right name to replace the branch containing 45
  • Commit
  • Remove the branch containing 45 and move it to the end of the branch we just created
  • Commit
  • Get revision 44 again
  • Create a new branch with the right name to replace the branch containing 46
  • Commit
  • Remove the branch containing 46 and move it to the end of the branch we just created
  • Commit

Also, as Ry4an pointed out in the comments, this only works if you haven't pushed the repository; if you have, the old branches will just come back. You can, however, replace the old repository with the new one. Depending on platform (github, kiln, etc.), how this works will vary, but it boils down to renaming and moving the old repository out of the way, then pushing all of the above changes into a new repository with the correct name, URL, etc.

OTHER TIPS

No, you can't change the branch label attached to a specific commit once you've pushed it, but you can add a new commit on that topological branch that will have the head named as you want:

hg checkout 46
hg branch what_I_wish_I_named_it
... maybe have to make a small edit here ...
hg commit

Then you'll have a new a commit whose ordinal revision number is high, but whose topological location is hanging off of 46 and it'll have the branch name you want.

Alternately, look into bookmarks, which are more like git-branches or auto-moving-tags. You could easily point a bookmark at revision 46 and it'll move forward whenever you commit on that branch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top