18

I am aware that rollbacks can remove commits from the latest changeset in a local repository. However, is it possible to remove all the latest commits since the previous push without having to re-clone the share repository?

Karan
  • 14,824
  • 24
  • 91
  • 157

3 Answers3

24

You can use the hg strip command, part of the mq extension:

hg strip REV

This will remove that revision + all its descendants.

Before you try this, make a copy/clone of the repository to experiment in.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • 1
    I believe that this should be the real answer to the question. The other one is a clone of the repo which was specifically requested NOT to be an option in the original question ("without having to re-clone"). As I was searching for the same solution as the original post this does answer my question and the other does NOT due to the clone... If the other is the answer the original poster wanted should the question be updated to reflect that and help out people while searching? – GazB Sep 24 '14 at 08:42
  • I agree with you GazB – Pascal T. Oct 23 '15 at 16:23
  • Instructions on how to enable the `Strip` extension is available on the [Hg Wiki for Strip](https://www.mercurial-scm.org/wiki/StripExtension). – Steve Eynon Feb 17 '16 at 20:53
13

You could make a new repo with hg clone:

hg clone -r last_good_changeset localrepo newlocalrepo
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This is my favorite answer because it doesn't require any extensions. one can easily clone a subset of a repo and it's nearly instantaneous. – Ry4an Brase Feb 07 '11 at 19:59
  • @Ry4an... just realized you actually did answer that one already: http://stackoverflow.com/questions/4172753/how-to-get-rid-of-some-changeset-in-hg/4173512#4173512 ! +1 on your original answer ;) – VonC Feb 07 '11 at 20:21
  • heh, no worries. I were better about these things I'd have tried to make the questions as a duplicate. – Ry4an Brase Feb 07 '11 at 21:20
  • I've tried this solution, and it fails with the error `conq: invalid repository syntax.` `strip` worked for me. – keflavich Nov 27 '11 at 18:21
  • Does this not fall under the "without having to re-clone" the original question asked not to have? :| – GazB Sep 24 '14 at 08:44
  • @GazB I agree, but it was selected by the OP, probably because strip isn't always appreciated, as explained in http://stackoverflow.com/a/4173512/6309. That being said, if `strip` works for you, go for it. – VonC Sep 24 '14 at 08:49
  • @VonC I understand the issues with Strip and for a LOT of cases I don't believe it should be used but there are a few times when you make a mistake (in my case logged 4 quick changes under the wrong user! So quickly exported, corrected user, strip and import solved a lot of confusion in the future.) ;) BUT my issue is really that the question and answers don't match and one should be changed for future searchers. After all that's what is all for right! ;) – GazB Sep 24 '14 at 15:33
1

If you are using mercurial eclipse, you can rollback once, then shelve those changes, then export the multiple sequential commits as patches, strip those commits, then import those patches in the same order, so in case you had conflicting patches, they overwrite each other in the desired way.

Finally you can unshelve your first rollback. This achieves the same effect as if you were rolling back more than once.

cool_guy2
  • 11
  • 1