Getting rid of Mercurials Multiple HEADS

1.4k Views Asked by At

I just started using hg Mercurial repository and stuck in a situation with multiple HEADS. I in the past pushed my code to repository as well but its missing from current code as well. It seems to me every time some body else push his code, my default head count increments on my side but i don't see such behaviour on anybody else machine. Can any body help it out how can i get rid of these heads and don't lose my pushes?

Note: i'm using MAC OSX with eclipse mercurial plugin.

2

There are 2 best solutions below

0
On

As far as I understand your problem right now, you are pushing to a repository and there are other guys using the same repository. Correct?

For me, it seems like that you aren't working on the latest commit, therefore multiple heads are created on your current branch. Note besides: there is some difference between heads and branches in Mercurial.

I can imagine something like this happens to you (assuming we are working on only one branch):

Your working copy:

1-2-3-4-5-6 (where number is revision)

so you're committing on r6, e.g. two commits 7' and 8'.
Now your working copy looks like this:

1-2-3-4-5-6-7'-8'

But in the meanwhile the shared repository you're all pushing to / pulling from looks like this:

1-2-3-4-5-6-7-8-9-10 (so r10 is the 'latest' commit published)

Now, if you're pushing to the shared repository, this happens:

            7'-8'
           /
1-2-3-4-5-6-7-8-9-10

And voila, now there are two different heads, called 8' and 10.

For the future, pulling first from the shared repository and updating on the latest commit will prevent you from this problem.

Now, as your question was how to resolve the multiple heads, there are different options, most easy for you is doing a simple merge.

hg help merge

Depending on if the heads are only locally (have a look at the phase of your heads / commits), you have more (maybe more elegant) options, e.g. rebasing.

In general, this is a good resource for getting started / deep with Mercurial.

0
On

Some good general information has been given but I'll give some MercurialEclipse specific info.

  • Key to understanding Mercurial is the history graph. (In the navigator view right click and select Team -> Show History). Note the left column which is the graph. Compare the graph after you commit with how it was before you commit. Also compare the graph before you pull with how it is after you pull.
  • In Mercurial committing a changeset doesn't mean it's visible to others. Only pushed changesets are visible to others
  • In general to fix this situation you should merge all the heads (Team -> Merge) and then push the new single head.
  • Once you are back to a single head one's workflow should
    • Before synchronizing commit your changes
    • Right click on the project -> Team -> Synchronize
    • In the synchronize view right click on the incoming node and select Pull and Update. This will then prompt you to merge with the incoming changes
    • When you are ready to push your changes (You should have a single head and nothing in incoming) you can do so in the synchronize view by right clicking on the outgoing node. Pushing a changeset pushes all ancestors.