Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a Mercurial queues patch to local changes only?

This answer shows how you can demote a commit to a patch, but how can I convert an mq patch to local changes only?

like image 847
Lstor Avatar asked Nov 20 '12 14:11

Lstor


2 Answers

Short answer

Make sure the patch is applied, then:

hg qrefresh nothing
hg qpop --keep-changes
hg qdelete "Name of patch"

Long answer

First, you need to make sure no changes are tracked by the patch. To do that, use

hg qrefresh nothing

nothing is just a random file name that is not in the repository. I usually use hg qref 0 for brevity. hg qrefresh accepts an optional file pattern. If it is given, the patch will track the changes that match the pattern - and only those. When nothing matches the file pattern, no changes will be tracked by the patch, and thus there will be local changes only.

Now you have a useless patch lying around, and you have some local changes. To clean up, you can do

hg qpop --keep-changes

to pop the patch even though there are local changes. Finally, to remove the dead, empty and unapplied patch you can use

hg qrm "Name of patch"

You can't remove an applied patch, which is why you need the hg qpop --keep-changes step.

(Note: hg qrm and hg qremove are aliases of hg qdelete.)

If using TortoiseHg

With TortoiseHg, exporting the patch to the clipboard (Workbench > right-click the patch > Export > Copy Patch), then unapplying the patch, and finally importing from the clipboard with the destination being "Working Directory" seems to work. Here are some screen captures demonstrating this procedure: enter image description here

like image 174
Lstor Avatar answered Oct 12 '22 17:10

Lstor


An arguably simpler alternative:

hg qfinish qtip
hg strip -k tip

That is, finish the patch and then remove the resulting commit while retaining its changes (the -k option to strip).

like image 23
duplode Avatar answered Oct 12 '22 16:10

duplode