How to undo "hg qnew"?
Asked Answered
A

3

9

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?

Anuradhapura answered 17/4, 2013 at 12:55 Comment(0)
E
13

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.

Eyler answered 18/4, 2013 at 7:28 Comment(0)
A
2

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
Anuradhapura answered 17/4, 2013 at 13:9 Comment(0)
R
2

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>
Rubberneck answered 19/4, 2013 at 9:5 Comment(4)
This extension seems very promising, and as a darcs user I like this way of selecting changes interactively. However, it doesn't answer my question - I needed to undo qnew that has already happened.Anuradhapura
If I understand well your question, you don't actually need to undo the qnew: you can directly use the qcrefresh command to exclude the changes that were not meant to be included. The excluded changes will remain as local changes, so after qcrefresh you can include them all in a new patch with qnew or even use qcrecord to only select a subset of them.Rubberneck
Perhaps I just don't understand how to use the extension properly. Could you please add a series of command starting with hg qnew on a modified repository, which ends as if qnew was never invoked? I tried to this using qrefresh before (which I suppose does the same thing as qcrefresh, only non-interactively), but without success.Anuradhapura
I've just edited my answer. With the qrefresh --include and --exclude options you can select which files to include in the patch qcrecord lets you choose the single hunks.Rubberneck

© 2022 - 2024 — McMap. All rights reserved.