How can I undo one change in Mercurial?

I made changes to the file in my mercurial project, which I would like to undo, but I would like to save some changes that occurred after it:

Revision 1: Original Revision 2: A change I made in error Revision 3: A change I want to keep 

I want to undo ONLY the changes in edition 2, leaving 1 and 3, and create a new version 4. What is the most โ€œmercurialโ€ way to do this?

Please note that yes, I could extract the back diff from version 2 and apply it to my working copy as a patch and fix this. I know. But I would like to find a way that the tool directly supports it.

+4
source share
2 answers

I think that if you look at the change log for the project (so you can see all the changes), you can select one revision and use the backout command to undo it.

(I have nothing at hand to test this, so it may be wrong.)

+5
source

You can use mq patches to edit your recent history. The following command would do the trick:

  hg qinit # initialises a queue
 hg qimport -r2: TIP # moves revisions from 2 onwards into patch management
 hg qpop -a # unapplies patches, leaving your actual checkout at r1
 hg qrm 2.diff # deletes the r2 patch (forever)
 hg qpush -a # applies all remaining patches again (ie the r3 patch)
 hg qfinish -a # moves applied patches back into official repository history

Such a thing is great for fixing an error in your local repository, but since you are changing the history, make sure that you did not click on someone else (or they did not pull from you) the original version before you corrected it.

If I understood correctly, hg backout instead make a new patch that undoes the previous change, thereby saving the changes in your history. This is a safer option, but less enjoyable if you often make local mistakes (like me).

+1
source

Source: https://habr.com/ru/post/1301641/


All Articles