Mercurial: How to deal with one branch that has two heads

What if one branch has two heads? I came to this situation weeks ago for some reason I didn’t merged them back then and just continued developing on one head. Now I want to get rid of the other head. What should I do? Should I just merge them after so many changesets?

  • SourceSafe Merge at the project level
  • Switch to another branch without changing the workspace files
  • Branch from a previous commit using git
  • Git: Howto move changes since last commit to a new branch
  • How to make individual pull requests vs “stacking” them on top of each other in Github?
  • Safely delete a TFS branch project
  • Deploying only changed part of a website with git to ftp (svn2web for git)
  • Servicing Branch in Standard Branch Plan
  • Managing release branches in Mercurial
  • Is it possible to view multiple git branches at the same time for the same project?
  • How to switch branches in eclipse without commiting changes
  • Sync svn and mercurial repo
  • 3 Solutions collect form web for “Mercurial: How to deal with one branch that has two heads”

    So you have this:

    o--o--o--A--B  <- older unnecessary head
           \
            1--2--3--4--5--6  <- newer ‘good’ head
    

    …and you don’t need A and B, absolutely, 100% sure. If you aren’t sure, and there are possibly salvageable things in A and B, better merge the heads to combine the changes. As Aaron said, Mercurial is good at it.

    Now you have two options:

    • get rid of the old head, or
    • do a dummy merge of two heads that ignores head B.

    If changesets A and B are present in other repositories you don’t control, e.g. if other people pulled A and B into their repositories, or you pushed A and B to a public repository (say, Bitbucket), then you’ve released A and B into the wild, and can’t get rid of them. You should do a dummy merge:

    $ hg up 6
    $ hg --config ui.merge=internal:local merge
    

    This will ignore any changes from A and B when merging.

    If, on the other hand, A and B are private, you can either strip them:

    $ hg strip A
    

    (Rev A and descendants stripped; enable the MQ extension to make strip available.)

    Or, make a new clone of your repository without changesets A and B:

    $ hg clone myrepo myrepo2-clone -r 6
    

    (Only rev 6 and ancestors added to the clone.)

    A head is created if you commit some changes (add a changeset to an existing changeset). If that happens several times for the same changeset, then several heads are created. This is nothing unusual or bad.

    The usual solution is to merge them. Mercurial is very good at merging. Chances are that the result will still compile and run without any manual work.

    Just run hg merge and then hg status and hg diff to see what changed between the two. If you like the result, commit it. If you don’t like it, update to either head to clean your workspace.

    To get rid of a head, the docs explain how to do that.

    Using MQ, you can also turn the second head into an independent branch (so you can keep it around but it won’t bother you). See this answer: How can I create a branch for a non-tip revision in Mercurial?

    If you need to keep the changes on the old branch, you should merge them, and it should not be a problem.

    Git Baby is a git and github fan, let's start git clone.