Tip: Removing a changset from a Mercurial repository

The "rollback" command only removes the latest changeset, if you want to remove/undo multiple changesets (and all of their descendants) from a repository you can use the "strip" method that comes with the "Mq" extension:

Step 1 - Enable the Mq extension
The Mq extension is distributed with Mercurial so to enable it just edit ~/.hgrc (in windows: C:\Users\UserName\.hgrc) and add the following lines:

  [extensions]
  mq=

If you use TortoiseHg, then you can just open the settings page, and in the Extensions section enable "mq".

Step 2 - Remove a changeset
Find the revision number of the changeset you wish to remove (via TortoiseHg or "hg log") and execute the following command:
  > hg strip revision-number
If you mess up you can restore the changeset by running:
  > hg unbundle .hg/strip-backup/filename

Comments

salty-horse said…
According to the docs, it also strips all of the descendants.

You could use the histedit extension to surgically remove a single changeset.
Anonymous said…
Exactly what I was looking for. Thanks!
Craig Weber said…
You might want to warn that using tortoiseHG to strip may strip changesets other than the changeset you selected and its descendants (probably depending on the mq version). Furthermore, hg unbundle cannot unbundle backed-up changesets (at least not consistently), but instead yields an "unknown parent" error. I wouldn't use strip unless you already have your changes pushed elsewhere.

Popular posts from this blog

Restart the Windows File Sharing Service to fix weird problems

WPF, ImageSource and Embedded Resources

SharpDevelop dark color scheme