Search code examples
mercurialtortoisehg

How to name an anonymous branch?


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.


Solution

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