How do you delete a commit in Mercurial?
MercurialMercurial CommitMercurial Problem Overview
I want to completely delete a Mercurial commit as if it was never entered in the repository and move back to my prior commit.
Is this possible?
Mercurial Solutions
Solution 1 - Mercurial
If it was your last commit and you haven't pushed it anywhere, you can do that with rollback
. Otherwise, no. Not really. Time to change your passwords.
Edit: It has been pointed out that you can clone from an older revision and merge in the changes you want to keep. That's also true, unless you have pushed it to a repo you don't control. Once you push, your data is very likely to be very hard to get back.
Solution 2 - Mercurial
You can try to remove mq info about your commit.
- For this you need to go File->Settings->Extensions.
- There check mq and restart gui.
- After that just right click on unneeded commit and ModifyHistory->Strip
Solution 3 - Mercurial
To edit the history I would use the Histedit Extension extension.
hg histedit 45:c3a3a271d11c
However keep in mind this only makes sense in a situation where you have not yet pushed the commits to the public repository, you own the public repository and/or you can account for all the clones out there. If you receive the following error:
abort: can't rebase immutable changeset 43ab8134e7af
It means that Mecurial thinks this is a public changeset (see phases) that has already been pushed - you can force it to be a draft
again doing:
hg phase -f -d 45:c3a3a271d11c
Solution 4 - Mercurial
I encounter this fairly often. I make a commit and then pull to push. But then there is something incoming that makes my newly made commit unnecessary. A plain hg rollback
isn't enough because it only undoes the pull...
This is the thing to do:
hg strip <rev>
Things are painless when you don't push your changesets anywhere.
Solution 5 - Mercurial
You can use "hg backout" to do a reverse merge basically. All options are discussed in the freely available book "Mercurial: The Definitive Guide":
http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html
Solution 6 - Mercurial
If it's more than one commit and/or you already pushed it somewhere else, you can clone your repository and specify the last changeset that should be cloned.
See my answer here how to do this:
https://stackoverflow.com/questions/3310222/mercurial-fix-a-borked-history
If you only committed locally and didn't push, you can just create a clone locally (as described in my link) and you're done.
If you already pushed to some remote repository, you would have to replace that with your clone.
Of course it depends if you are able (or allowed) to do this.
Solution 7 - Mercurial
If using tortoise you can use modify history > strip...
Solution 8 - Mercurial
Yes. Unless I am mistaken, as of v2.3 (rel. 2012/08/01) you can use the HisteditExtension with a drop
command to drop a commit, along with strip
or backout
to remove changes.
A simple Google search on the feature: https://www.google.com/webhp#q=histedit+drop