Search code examples
mercurialbranchhead

Central Hg has multiple heads on default branch, how can I prevent that?


While cleaning up a certain Hg (Mercurial) repository, I noticed that an old revision (actually 4 years old) shows a branch going nowhere on the default branch.

I thought it wasn't possible to branch the same branch (I mean, you can have a new head on a new branch, but not on the same branch). What is happening here and what did the (then working for me) programmer do here incorrectly, and more importantly, how to prevent it?

enter image description here


Solution

  • It always has been possible (or at least since mercurial around 0.9); mercurial is not git where such thing is much more complicated to handle. You can work without any (named) branches in mercurial and have as many anonymous heads per branch as you care to create. Simply update to a non-head version and start to commit and - voilà - you created a new head.

    EDIT to add: You can prevent adding additional heads to your repository if you apply an appropriate pretxnchangegroup hook which checks for the presence of additional heads in the incoming changesets. There are a couple of old stackoverflow answers to that:

    How do I prevent someone from pushing multiple heads?

    How can I create a mercurial hook that prevents new heads?

    to name just two