hg equivalent of git stash

Tom Anderson tom.anderson at e2x.co.uk
Mon Dec 12 10:12:40 CST 2011


On 12 December 2011 15:15, anatoly techtonik <techtonik at gmail.com> wrote:
> Quoting http://markmail.org/message/lglewvoffuxnffbz
>
> On Jan 12, 2008 3:27:01 pm, Matt Mackall wrote:
>>
>> On Sat, 2008-01-12 at 17:13 -0600, Phillip Koebbe wrote:
>>
>>> I was reading earlier today about "git stash" and was thinking it
>>> would be very useful to me. Is something like that available in hg?
>>
>> You might be interested in mq, which is about a million times more
>> useful.
>
> Among million use cases for mq, can anybody explain the mq equivalent of git
> stash?
>
> My use case: I want to put my current changes away temporarily (into stash),
> do some unrelated changes, commit them and then get my previous changes back
> (removing them from stash). How do I do this with mq?

Some combination of qnew, qrefresh, qpop, and qpush.

Try this:

$ # first set up a repo and enable MQ
$ hg init anatoly
$ cd anatoly
$ cat >.hg/hgrc <<EOF
[extensions]
mq =
EOF
$ # some base data
$ echo apples >fruit
$ echo cheddar >cheese
$ hg add .
adding cheese
adding fruit
$ hg commit -m 'initial commit'
$ # some work in progress
$ echo bananas >fruit
$ hg status
M fruit
$ cat fruit
bananas
$ # stash!
$ hg qnew stash
$ hg qpop -a
popping stash
patch queue now empty
$ hg status
$ cat fruit
apples
$ # some unrelated changes
$ echo brie >cheese
$ hg commit -m 'second commit'
$ # unstash!
$ hg qpush stash
applying stash
now at: stash
$ hg status
$ cat fruit
bananas

Having done that, you have a patch called stash, so you can't do qnew
again. You could either pick a new name, or do a qrefresh instead of a
qnew (i think).

Roughly, in this situation:

qnew = "create a new patch, and add all my current uncommitted changes
to that patch"
qrefresh = "add all my current uncommitted changes to an existing patch"
qpop = "remove a patch from the working directory"
qpush = "add a patch to the working directory"

Because MQ allows multiple patches, it treats patches as named
objects, which makes it a bit more verbose than Git's stash for this
use case. Note that there other extensions which provide a simpler
stash behaviour which are more concise.

tom

-- 
Tom Anderson         |                e2x Ltd, 1 Norton Folgate, London E1 6DB
(e) tom at e2x.co.uk    |    (m) +44 (7960) 989794    |    (f) +44 (20) 7100 3749


More information about the Mercurial mailing list