Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hg: delete latest commits [duplicate]

Tags:

undo

mercurial

I've used Git in the past and I'm a Hg noob:

I have following repository structure:

o [> default] commit A
|
o commit B
.
.
.
o <a-tag]
|

I've updated to the commit with the a-tag and committed a few other commits. Now I have

o [> default] commit C
|
o commit D
|
|  o [default] commit A
|  |
|  o commit B
|  .
|  .
|  .
| /
o <a-tag]
|

Now (before pushing) I realize that I had my commits commit C and commit D based on the wrong commit. How can I go back to the initial state (without having to re-clone the repository) dropping these commits commit C and commit D (pendant to git reset --hard a-tag)?

like image 366
Mot Avatar asked Nov 19 '11 16:11

Mot


1 Answers

You can use 'strip' to permanently delete commits and all it's descendants. In your case you need to specify the id of "D" revision:

hg strip -r D

Note: mq extension must be turned on:

[extensions]
mq=

Mercurial backups bundles of the stripped changesets in .hg/strip-backup so this operation is rather safe.

like image 153
Ruslan Yushchenko Avatar answered Sep 21 '22 00:09

Ruslan Yushchenko