hg equivalent of git stash

anatoly techtonik techtonik at gmail.com
Mon Dec 12 21:32:34 UTC 2011


On Mon, Dec 12, 2011 at 8:46 PM, Brendan Cully <brendan at kublai.com> wrote:

> On Monday, 12 December 2011 at 20:09, anatoly techtonik wrote:
> > On Mon, Dec 12, 2011 at 7:40 PM, Brendan Cully <brendan at kublai.com>
> wrote:
> >
> > > On Monday, 12 December 2011 at 19:13, anatoly techtonik wrote:
> > > > On Mon, Dec 12, 2011 at 6:35 PM, Masklinn <masklinn at masklinn.net>
> wrote:
> > > >
> > > > > On 2011-12-12, at 16:15 , anatoly techtonik 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?
> > > > >
> > > > >     > hg qnew -f [-i] [-m "reminder message"] some-patch-name
> [files…]
> > > > >    > hg qpop
> > > > >
> > > >
> > > > 'hg diff' doesn't show anything, so this solution is either wrong or
> > > > incomplete (thanks for the answer, I appreciate it, but it doesn't
> help
> > > > people who will be searching for 'git stash' recipe for mercurial).
> > >
> > > You've popped the patch at this point. It's tucked away in a patch
> > > file in .hg/patches right now. If you want to see the diff, the
> > > simplest way is to 'hg qpush' then 'hg qdiff'. Alternatively, 'cat
> > > .hg/patches/stash' is equivalent to git stash show.
> > >
> >
> > Thanks, but I don't want to just see the diff - I need to restore my
> > working copy to the state it was before I stashed changes.
> >
> > When you want to put the changes back into the working directory at
> > > the very end, run 'hg qref -X .' from the root to transfer them out of
> > > the patch. (Admittedly, this invocation has git-like clarity.)
> > >
> >
> > I am puzzled. After 'hg qref -X .', 'hg qdiff' and 'hg diff' show the
> same
> > info. Did I break something?
> > Well, I started from. Your solution doesn't work either:
> >
> > # put my changes into stash (mq patch named 'stash')
> > > hg qnew stash
> > > hg qpop
> > ...
> > # pop my changes out of stash
> > > hg qpush
> > > hg qref -X .
> > ## `hg qdiff` and `hg diff` now show identical info
>
> qdiff includes the working directory changes too. If it's in hg
> diff, it's in your working directory. If you cat .hg/patches/stash,
> however, that should be empty.
>
> > > hg qdel stash
> > abort: cannot delete applied patch stash
> > > hg qpop
> > abort: local changes found, refresh first
> >
> > catch22 =)
>
> Hmm, I thought I remembered that qpop didn't object unless the patch
> file touched modified files in the working directory (which it
> wouldn't here since the patch file will be empty). I guess you would
> have to qpop -f
>

Gotcha! To summarize this part of solution:
# stashing
git> git stash save "work in progress"
hg> hg qnew stash-work-in-progress
hg> hg qpop

# restoring
git> git stash apply
hg> hg qpush
hg> hg qrefresh -X .
hg> hg qpop --force
hg> hg qdelete stash-work-in-progress

This isn't a beautiful user experience, but it should work.
>

Yes. Not as beautiful as Matt's ad promised. =) You also need to type in
your patch name in the last command, so it becomes much harder to be
automated.

This ugliness is the reason people have written the shelve and attic
> extensions.
>

At least we now all agree that this is ugly and user experience is pretty
bad compared to Git. The question is if you are going to fix that?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20111213/21a8b654/attachment-0002.html>


More information about the Mercurial mailing list