Abandoning changes without deleting from history

I know you don't want to work with branches at this stage, but that's exactly what you've done. When you went back to an earlier version and committed something that worked you created a branch - an unnamed branch, but a branch all the same.


There's no problem with just carrying on just as you are and not worrying about having multiple heads, but if you want to tidy things up so you don't accidentally pick the wrong head one time then you can kill off the old branch.

There's a good section in the Mercurial documentation that takes you through a number of options around Pruning Dead Branches.

I think the best option for you is to mark the old branch as "closed". If your old head is revision "123" then:

hg update -r 123
hg commit --close-branch -m 'Closing old branch'
hg update -C default

First of all, type:

hg heads

Imagine, you have three heads listed:

changeset:   223:d1c3deae6297
user:        Your name  <[email protected]>
date:        Mon Jun 09 02:24:23 2014 +0200
summary:     commit description #3

changeset:   123:91c5402959z3
user:        Your name <[email protected]>
date:        Sat Dec 23 16:05:38 2013 +0200
summary:     commit description #2

changeset:   59:81b9804156a8
user:        Your name <[email protected]>
date:        Sat Sep 14 13:14:40 2013 +0200
summary:     commit description #1

Let's say, you want to keep the last head active (223) and close the rest.

You would then do as follows:

Close head #59

hg up -r 59
hg ci --close-branch -m "clean up heads; approach abandoned"

Close head #123

hg up -r 123
hg ci --close-branch -m "clean up heads; approach abandoned"

Commit the changes

hg push

Don't forget to switch to the right head at the end

hg up -r 223

And you're done.


Update your repository to the head with the revision that you want to forget about, then use hg commit --close-branch to mark that (anonymous) branch as closed. Then update to the head of the branch that you do want, and continue working.

You can still see the closed branch if you use the -c option to hg heads, but it won't show up by default and hg merge will know not try to merge with the closed head.

You will need to use hg push --force the first time you push this closed head to another repository since you are actually create additional heads in the remote repository when you push. So tell Mercurial that this is okay with --force. People who pull the closed head wont be bothered by any warnings.

Tags:

Mercurial