6

What are the equivalent commands in hg for git stash, git stash apply and git stash pop ?

Aastha Dahal
  • 329
  • 2
  • 11
  • 1
    See `shelve` — also try a general search *first*. https://stackoverflow.com/a/10001059/2864740 , https://markheath.net/post/git-stash-for-mercurial-users – user2864740 Oct 04 '21 at 03:02
  • Note that Git's `git stash` is absurdly complicated and `hg shelve` isn't, so you might not consider these "equivalent". – torek Oct 04 '21 at 03:30

2 Answers2

7

Temporarily putting away your changes:

Mercurial hg commit [-s] is preferred hg shelve is not recommended

Git git stash

Listing changes put away

Mercurial hg xl or hg shelve -l

Git git stash list

Viewing a put-away change

Mercurial hg diff -c <rev> or hg shelve -p <name>

Git git stash show <name>

Restoring put-away changes

Mercurial hg uncommit --no-keep or hg unshelve

Git git stash pop

Restoring put-away changes but keeping them in the stack

Mercurial Continue to amend or hg uncommit --keep or hg unshelve --keep

Git git stash apply

Sulav Timsina
  • 703
  • 7
  • 20
  • 5
    I use hg shelve quite often, why do you say it is not recommended? – StayOnTarget Oct 05 '21 at 13:13
  • What version of Hg supports these commands? I'm running 3.5.2 (on windows) & uncommit, hg xl, etc are not valid commands in that version. – raddevus Feb 15 '22 at 19:08
  • Mercurial Version 5.1 on Windows. See: https://wiki.mercurial-scm.org/ShelveExtension where it says, "As of Mercurial 5.1, shelve is part of Mercurial core and is enabled by default." However, there is a heading at the top of the page, which discusses using it as an extension: "This extension is distributed with Mercurial 2.8 and later. If you are using an earlier version of Mercurial, see ThirdPartyShelveExtension." That last set of keywords links here: https://wiki.mercurial-scm.org/ThirdPartyShelveExtension – Clomp May 26 '23 at 23:59
0

I use the mq extension for this (which is not enabled by default). This extensions gives me the possibility to have a set of (not yet finished) patches, I keep on top of the "official" history.

What you would do with git stash is now hg qnew »patchname« && hg qpop, git stash pop now becomes hg qpush. The biggest directly noticeable difference is, that you have to give your patch a name in mercurial, while the git variant is happy to live anonymously.

Steve Losh did a more in depth article what this extension also can do.

Rudi
  • 19,366
  • 3
  • 55
  • 77