Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert last commits and keep changes in mercurial?

Tags:

mercurial

I have three commits 1, 2 and 3. How can I rollback 2 and 3 and still keep the changed files of them??

1---2---3

=> 1 and changed files of 2 and 3
like image 253
nguyenngoc101 Avatar asked Apr 02 '15 13:04

nguyenngoc101


2 Answers

If you use TortoiseHg, you can achieve this like that:

  1. Enable strip extension from Settings -> Extensions
  2. Give Strip... command from -> 'Modify History' -> 'Strip'.
  3. Check Do not modify working copy during strip (-k/--keep) option.
  4. Click Strip button.
like image 178
ismailarilik Avatar answered Sep 18 '22 21:09

ismailarilik


You use the strip command:

strip changesets and all their descendants from the repository

with the --keep option:

-k --keep do not modify working copy during strip

And since strip is destructive of history it's not enabled by default. You enable it by adding these lines to your ~/.hgrc file:

[extensions]
strip =

So in this case you'd do hg strip --keep 2

Note: requires Mercurial 2.8 or later. Before that you need to put mq = in the .hgrc instead.

like image 37
Ry4an Brase Avatar answered Sep 17 '22 21:09

Ry4an Brase