431

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?

4b0
  • 20,627
  • 30
  • 92
  • 137
Jesse Atkinson
  • 9,456
  • 13
  • 40
  • 44

10 Answers10

578
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

Bob Gilmore
  • 11,154
  • 13
  • 49
  • 52
  • 33
    My only nit with this answer is that the question asks how to `pop` a specific stash and this command `apply`s the stash rather than popping it. The difference being that a pop both applies the stash to the code and deletes the stash itself. – Grant Humphries Feb 16 '18 at 20:00
  • Not working for me. Getting error "unknown option: -encodedCommand" – Yuvraj Patil Mar 12 '18 at 06:30
  • 19
    [Since the version 2.11 you can type:](https://stackoverflow.com/questions/1910082/git-stash-apply-version/44451133#44451133) `git stash apply n` – Dwhitz Apr 05 '18 at 12:49
  • Please update your answer, its now `git stash apply n` – Hafiz Temuri Apr 01 '20 at 02:29
205

You need to escape the braces:

git stash pop stash@\{1\}
isherwood
  • 52,576
  • 15
  • 105
  • 143
Vasiliy
  • 15,653
  • 8
  • 64
  • 114
135

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
Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
54

On Windows Powershell I run this:

git stash apply "stash@{1}"
Robert Brooker
  • 1,668
  • 20
  • 20
17

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

git stash pop stash@"{1}"
owenmck
  • 378
  • 3
  • 9
12

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

git stash pop "stash@{0}"
Kenan
  • 11,783
  • 8
  • 39
  • 49
9

Version 2.11+ use the following:

git stash list

git stash apply n

n is the number stash@{12}

manish kumar
  • 4,037
  • 2
  • 32
  • 46
9

I have 2.22 installed and this worked..

git stash pop --index 1
markg
  • 279
  • 4
  • 8
  • 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 [...] -- [...]' – Dave Doga Oz Apr 17 '20 at 17:52
  • warning on Poping your stashes – shervinox Dec 18 '20 at 22:04
6

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}
Vaibhav Vishal
  • 5,575
  • 7
  • 25
  • 43
Jabbi Syed
  • 111
  • 1
  • 3
0

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.

PaulBunion
  • 135
  • 2
  • 12