How to remove certain changesets from a specific Mercurial clone?

Mercurial

Mercurial Problem Overview


I have a clone of a central repo at rev 2048. I want to remove the last 10 changesets on my local repo as if I was back in time two weeks ago. I suppose I could delete my local repo and do "hg clone -rev 2038" but that would be long (cloning the repo takes several minutes). Is there a way to just "unpull" some changesets?

Notes:

  • I'm not trying to backout the changesets. I'll eventually pull those changesets again from the central repo.
  • I'm not trying to update the working directory to an earlier version; I really want to affect the repository.
  • I don't have any outgoing changesets or pending modifications in my current repo and working directory.

Mercurial Solutions


Solution 1 - Mercurial

Use the strip command:

hg strip -r 2039

This command is provided by the StripExtension. It is distributed as part of Mercurial 2.8 and later, but you do need to enable it first by adding the following lines to your .hgrc or Mercurial.ini:

[extensions]
strip =

Before Mercurial 2.8, it was part of the MqExtension.

To prevent you from accidentally destroying history, the command will generate a backup bundle in .hg/strip-backup/ which you can hg unbundle again if desired.

Solution 2 - Mercurial

Cloning your local repo should be fast. I assume "several minutes" refers to a remote repo?

You can use hg clone <local repo> <new repo> -r <revision> to only clone up to a certain revision.

Solution 3 - Mercurial

To remove a changeset that was already committed and pushed use :

hg backout -r (changeset number)

To remove a changeset that was committed but not pushed use :

hg strip -r (changeset number)

Solution 4 - Mercurial

For versions previous to Mercurial 2.8, the Strip was part of the MqExtension.
In case you need to Enable the old MQ Extensions, you can do it by adding this:

[extensions]

hgext.mq =

to your ~/.hgrc (or mercurial.ini) file.

The Strip information used to be here but now it can be found [here] 2.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSylvainView Question on Stackoverflow
Solution 1 - MercurialWim CoenenView Answer on Stackoverflow
Solution 2 - MercurialMark TolonenView Answer on Stackoverflow
Solution 3 - MercurialShwetaView Answer on Stackoverflow
Solution 4 - MercurialYmagine FirstView Answer on Stackoverflow