Is there any way to delete local commits in Mercurial?
Enable the "strip" extension and type the following:
hg strip #changeset# --keep
Where #changeset#
is the hash for the changeset you want to remove. This will remove the said changeset including changesets that descend from it and will leave your working directory untouched. If you wish to also revert your committed code changes remove the --keep
option.
For more information, check the Strip Extension.
If you get "unkown command 'strip'" you may need to enable it. To do so find the .hgrc
or Mercurial.ini
file and add the following to it:
[extensions]
strip =
Note that (as Juozas mentioned in his comment) having multiple heads is normal workflow in Mercurial. You should not use the strip command to battle that. Instead, you should merge your head with the incoming head, resolve any conflicts, test, and then push.
The strip
command is useful when you really want to get rid of changesets that pollute the branch. In fact, if you're in this question's situation and you want to completely remove all "draft" change sets permanently, check out the top answer, which basically suggests doing:
hg strip 'roots(outgoing())'
If you are using Hg Tortoise just activate the extension "strip" in:
- File/Settings/Extensions/
- Select strip
Then select the bottom revision from where you want to start striping, by doing right click
on it, and selecting:
- Modify history
- Strip
Just like this:
In this example it will erase from the 19th revision to the last one commited(22).