tags:

views:

202

answers:

4

There is a commit that just didn't work, so I want to abandon it without deleting it from history.

I have updated from an earlier revision and committed, thus creating a new head.

I don't have branches, I don't want branches, I just want to simply go on with the new head exactly as it is, nothing fancy, no merge, no worries, just go on forgetting the previous one.

I can't seem to find how to do that, and I'm starting to believe it can't be done. All I find is stuff about branches, or stuff about merging.

+5  A: 

You want to use the Backout command, this removes the changes made by the change set from any child changeset

Check this out for a good explination Mercurial Backout

msarchet
This is exactly the right answer. Backout add the inverse of a changeset, undoing the working and giving you a commit message to remind yourself why you didn't like the idea.
Ry4an
I actually disagree -- abandoning work on one head and starting over from a good starting point seems like a cleaner work pattern than using backouts. Especially since you cannot backout more than one changeset at a time.
Martin Geisler
@Martin Geisler, well I agree with this in general, but the OP stated he wanted to abandon the changes without branches
msarchet
msarchet: okay, I see. I focused more on the part about going on with the new head. For quickly canceling a single changeset, backout (or plain `hg revert --all --rev GOODREV`) are fine options.
Martin Geisler
@Martin Geisler yea I'm all for branching just sometimes nuking a bad change is the best
msarchet
it might be useful sometimes, but that was not really what I wanted. Thanks anyway :)
Lo'oris
+6  A: 

Update your repository to the head with the revision that you want to forget about, then use the --close-branch option to hg commit to mark that 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.

Niall C.
@Niall C. won't that only work if he has marked that as a named branch? I'm assuming from what he's saying he did that it is in default
msarchet
@msarchet: it works for anonymous branches too.
Niall C.
@Niall C. cool did not know that
msarchet
but... that's not true, I still get both heads listed when I call `hg heads`... I'm using mercurial 1.4.3, is that a newer feature?
Lo'oris
@Lo'oris: I'm using 1.6.3. The release notes (http://mercurial.selenic.com/wiki/WhatsNew) say there were changes to the `heads` command in 1.5.0; this might have been part of them.
Niall C.
@Niall you're right: upgrading to 1.6.3 fixed it, thanks!
Lo'oris
A: 

Since it is a head it will always show up during push etc. There's no built-in way to ignore a certain head. Commands like push take a rev specifier that you can use to make it only push changes predecessing a revision (instead of the full graph).

But in the longer term, I find this is not a workable solution. The best thing I can recommend is to hg export the changeset into a bundle and then hg strip it (you could also locate the strip-backup, just see the commands output for where that got stuffed). Keep the bundle around as a backup.

Another solution would be to push the changeset into a "historical" clone of your repository that contains all your dead-end developments like this. Have a separate, clean repo for your trunk.

Johannes Rudolph
Hg strip would remove it from history, which is what he wisely and correctly said he doesn't want to do. Blind allies you wish you didn't go down are still valid work, and they shouldn't be in another clone, they should be proudly displayed in your working clones.
Ry4an
You are not removing them from your public clone, only from your "trunk" repository where merging shouldn't be an issue.
Johannes Rudolph
+1  A: 

I know you don't want to work with branches at this stage, which is fine, 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 you old head is revision "123" then:

hg update -r 123
hg commit --close-branch -m 'Closing old branch'
hg update -C default
Nick Pierpoint
Blurgh - just saw @Niall's answer after I'd entered. Will upvote Niall's and mine can languish in the zero points pool. :)
Nick Pierpoint