How to Git stash pop specific stash in 1.8.3?
Asked Answered
M

10

548

I just upgraded Git. I'm on Git version 1.8.3.

This morning I tried to unstash a change 1 deep in the stack.

I ran git stash pop stash@{1} and got this error.

fatal: ambiguous argument 'stash@1': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'

I've tried about 20+ variations on this as well as using apply instead of pop with no success. What's changed? Anyone else encounter this?

Multifaceted answered 3/7, 2013 at 17:12 Comment(2)
Did you try escaping the {}'s?Aft
With Git 2.11 (Q4 2016), you can now use git stash pop 1: see my answer belowMartensite
U
741
git stash apply n

works as of git version 2.11

Original answer, possibly helping to debug issues with the older syntax involving shell escapes:

As pointed out previously, the curly braces may require escaping or quoting depending on your OS, shell, etc.

See "stash@{1} is ambiguous?" for some detailed hints of what may be going wrong, and how to work around it in various shells and platforms.

git stash list
git stash apply stash@{n}

git stash apply version

Upperclassman answered 3/7, 2013 at 17:51 Comment(5)
My only nit with this answer is that the question asks how to pop a specific stash and this command applys the stash rather than popping it. The difference being that a pop both applies the stash to the code and deletes the stash itself.Trituration
Not working for me. Getting error "unknown option: -encodedCommand"Drunk
Since the version 2.11 you can type: git stash apply nMayberry
Also, you can type git stash pop '<stash-ref>' where stash-ref is like stash{0}. Don't forget the quotesSingultus
This also works for commands like git stash show 1, which will do git stash show with the second item on the stash stackPeeples
P
239

You need to escape the braces:

git stash pop stash@\{1\}
Pentlandite answered 3/7, 2013 at 17:51 Comment(1)
or just put into doubles quote, e.g. git stash pop "stash@{1}"Histiocyte
M
156

If you want to be sure to not have to deal with quotes for the syntax stash@{x}, use Git 2.11 (Q4 2016)

See commit a56c8f5 (24 Oct 2016) by Aaron M Watson (watsona4).
(Merged by Junio C Hamano -- gitster -- in commit 9fa1f90, 31 Oct 2016)

stash: allow stashes to be referenced by index only

Instead of referencing "stash@{n}" explicitly, make it possible to simply reference as "n".
Most users only reference stashes by their position in the stash stack (what I refer to as the "index" here).

The syntax for the typical stash (stash@{n}) is slightly annoying and easy to forget, and sometimes difficult to escape properly in a script.

Because of this the capability to do things with the stash by simply referencing the index is desirable.

So:

git stash drop 1
git stash pop 1
git stash apply 1
git stash show 1
Martensite answered 11/11, 2016 at 7:52 Comment(0)
C
81

Update

From git 2.11 just use the number:

git stash apply 1

Orginal

On Windows Powershell I run this:

git stash apply "stash@{1}"
Catron answered 1/7, 2015 at 22:13 Comment(2)
Works on ubuntu linux tooCounselor
also works on Mac OS X. I like this better than escaping single characters.Ratio
M
19

As Robert pointed out, quotation marks might do the trick for you:

git stash pop stash@"{1}"
Menken answered 18/8, 2015 at 2:22 Comment(0)
O
16

If none of the above work, quotation marks around the stash itself might work for you:

git stash pop "stash@{0}"
Opulent answered 24/4, 2017 at 15:0 Comment(0)
S
15

I have 2.22 installed and this worked..

git stash pop --index 1
Successful answered 3/10, 2019 at 23:55 Comment(3)
It doesn't work.. $ git stash pop --index 1 fatal: ambiguous argument '1': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'Thither
warning on Poping your stashesDocent
this worked for me in windows powershellPriam
C
12

Version 2.11+ use the following:

git stash list

git stash apply n

n is the number stash@{12}

Crosse answered 5/9, 2019 at 5:40 Comment(0)
S
11

First check the list:-

git stash list

copy the index you wanted to pop from the stash list

git stash pop stash@{index_number}

eg.:

git stash pop stash@{1}
Sorci answered 5/2, 2019 at 11:10 Comment(0)
C
4

I've seen this answer a few times in this list, but just to be explicitly clear, at least as of git version 2.33.0, git stash pop stash@{n} is valid. No escaping necessary.

Clipping answered 7/3, 2022 at 17:58 Comment(3)
Might depend on the shell you use, right?Terr
@Terr Yeah I suppose that's possible. I'm just using whatever comes with the Git CLI for Windows within VS Code.Clipping
Yes, that explains. In some shells the curly braces need to be escaped or the whole argument quoted. Other than that this generally worksTerr

© 2022 - 2024 — McMap. All rights reserved.