Search code examples
mercurial

How to delete a head?


I have pushed some files by mistake and it shows different heads in main repository. How can I delete that head?


Solution

  • I don't think that you actually want to delete the heads. If you do that, you will lose the work that was done in those branches.

    You probably want to merge the heads back into one branch.

    Say that you have a tree like this:

    o  4 : Head 1
    |
    o  3 : Another commit
    |  
    | o 2 : Head 2
    | |
    |/
    o  1 : A commit
    |
    o  0 : Initial commit
    

    To get rid of the additional head without losing the work contained within it you would merge the two heads (revisions 2 and 4 in this example) like this:

    hg update 4
    hg merge 2
    hg commit -m "Merge"
    

    That will create another commit which has all the changes in revisions 2, 3 and 4 in a single head like this:

    o     5: Merge
    |\
    o |   4 : Head 1
    | |
    o |   3 : Another commit
    | | 
    | o   2 : Head 2
    | |
    |/
    o     1 : A commit
    |
    o     0 : Initial commit
    

    This is standard procedure when multiple developers work on the same repository.