Can you close a Mercurial branch without updating to it first?

Yes you can, but this is not documented anywhere. I’ve used this technique for a long time, don’t worry, it is safe.

Instead of updating, you can issue the following commands

hg debugsetparent <revision>
hg branch <branchOfRevision>

Note that the order is important. This will make your repo think it is on the new revision, while all your files are from the initial one. After that, you can use the --close-branch commit, but use the -X * option to make an empty commit.

hg commit --close-branch -X * -m "Closing branch."

Now, simply get back to your previous head, like nothing happened.

hg debugsetparent <InitialRevision>
hg branch <branchOfInitialRevision>

Finally, if you have sub-repos, you might want to temporarily rename the .hgsub file before committing the --close-branch, and rename back afterward.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)