Search code examples
mercurialbranching-and-merging

Stuck with two default branches in Mercurial after broken branch commits


I've come across a difficulty at work (as presented in the simplified sketch below). During the creation of a branch the default for some reason got stuck as a parent to a branch, but still keeping a default branch separately (that is the default branch we're using going forward). This has left us with two default branches.

Someone mistook how to commit changes before branching, so we ended up merging changes made in branch1 into a branch2.

I've been looking into Mercurial: the definitive guide to see if this is a resolvable issue, but couldn't find out what commands regarding backing out or closing that would help. The easiest way would be if it's somehow possible to rename the left-over default branch.

What is the best and/or easiest way to resolve this?

I'm preparing the merging of development branches into the correct default branch and want to have this headache fixed before I start any major merging that could make it even more difficult to fix this in the future.

branch problems


Solution

  • Remember that the branch names are just labels put on the commits — there's nothing really broken about your graph. The branch names doesn't affect what happens when you merge, only the file content is important when merging.

    That being said, you can close the extra head on default, the one below branch1:

    $ hg update "min(heads(branch(default)))"
    $ hg commit --close-branch -m "closing this head"
    

    That will leave a dangling close changeset in your graph, which is fine. The close changeset will hide the head from hg heads and commands such as hg merge will then no longer suggest to merge with this head.