views:

98

answers:

3

I've encountered a problem in my Mercurial workflow when experimenting with implementing a certain feature. I was trying three different approaches to implementing the feature by commiting each update followed by updating to the previous changeset - so I end up with three different branches.

Once I have chosen one of the branches to be the "correct" implementation of the feature, I want to remove the other branches so that I don't have multiple heads. How do I do this in a simple way? I ended up merging the three branches together which was pointless because I only ever wanted the code from one branch.

+1  A: 

The following closes a branch

hg commit --close-branch

It will not show up in

hg branches or hg heads
pyfunc
It still shows up in hg heads. I haven't actually created a branch actually, just a 3 headed hydra!
Tarski
It works for me. Do you happen to have `-c` as `hg heads`'s default option?
Geoffrey Zheng
Also There is a bug in Mercurial 1.3.1 , this works well on latest versions of Mercurial (hg heads).
pyfunc
+1  A: 

Enable the built-in mq extension and run hg strip.

@pyfunc's answer keeps the closed branches in revision history, which is what I would actually do unless your unwanted branches are huge.

Geoffrey Zheng
+1  A: 

In addition to hg strip from the mq extension, you can simply use the standard clone command:

$ hg clone -r the-good-head . ../pruned

to get a clone in ../pruned that holds only the good head (and all its ancestors). This is the safe, built-in way to prune things in Mercurial and it has the advantage that you still have both repositories intact after the command. So if you make a mistake, then just delete the ../pruned clone.

Martin Geisler