Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo "hg qnew"?

I issued hg qnew without realizing that it includes any outstanding changes into the patch. I'd like to back that out and pick only specific changes using hg qrecord. How can I undo qnew?

like image 878
Petr Avatar asked Apr 17 '13 12:04

Petr


3 Answers

Your answer definitely works — with newer Mercurial's you can use hg strip --keep to avoid doing the import step:

$ hg strip --keep .
$ hg qdelete patch-name

The --keep flag makes strip ignore the working copy while working, that is, it deletes the commit (like hg qpop would do) but it doesn't undo the changes to the files. After stripping you still have the patch in your series (unapplied) and you can then delete it.

like image 50
Martin Geisler Avatar answered Nov 09 '22 12:11

Martin Geisler


I've found an anwer here:

hg qpop
hg import --no-commit .hg/patches/patch-name
hg qdelete patch-name

Please add a better way, if you know.

Update: Based on Aldo's answer, there is another way:

hg qnew test
# We can undo the above qnew as:
hg qrefresh -X '*'
hg qpop -f
hg qdelete test
like image 24
Petr Avatar answered Nov 09 '22 12:11

Petr


If you just want to undo the latest qnew retaining all your local changes, one option is:

qcrefresh 123
hg qpop -f
hg qdelete <name of the patch>

Notice that 123 is just a random string: you are telling mercurial to only include the (hopefully nonexistsnt) 123 file in the current patch. Newer versions of Mercurial When you issue will issue a warning about the fact 123 file does not exist, but this is exactly what we want here.

If you want to retain some of the changes in the current path, you can use the qcrefresh command from the crecord extension, which allows to graphically select the changes to be included in the current patch. You need to download it from Bitbucket, extract the archive and configure it in .hgrc:

[extensions]
crecord = <path/to/crecord/package>
like image 2
Aldo Avatar answered Nov 09 '22 13:11

Aldo