What is the Mercurial(hg) equivalent of git stash?
Asked Answered
G

2

9

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

Greenback answered 4/10, 2021 at 2:56 Comment(2)
See shelve — also try a general search first. https://mcmap.net/q/386404/-hg-shelve-equivalent-of-git-stash-drop , markheath.net/post/git-stash-for-mercurial-usersUpbraid
Note that Git's git stash is absurdly complicated and hg shelve isn't, so you might not consider these "equivalent".Spermato
T
9

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

Two answered 4/10, 2021 at 3:11 Comment(3)
I use hg shelve quite often, why do you say it is not recommended?Inquisitionist
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.Isabelleisac
Mercurial Version 5.1 on Windows. See: 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: wiki.mercurial-scm.org/ThirdPartyShelveExtensionKlenk
R
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.

Rappee answered 9/10, 2021 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.