[git] How to Git stash pop specific stash in 1.8.3?

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?

This question is related to git escaping git-stash

The answer is


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


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

Version 2.11+ use the following:

git stash list

git stash apply n

n is the number stash@{12}


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

git stash pop stash@"{1}"

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}

You need to escape the braces:

git stash pop stash@\{1\}

On Windows Powershell I run this:

git stash apply "stash@{1}"

I have 2.22 installed and this worked..

git stash pop --index 1

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

git stash pop "stash@{0}"

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to escaping

Uses for the '&quot;' entity in HTML Javascript - How to show escape characters in a string? How to print a single backslash? How to escape special characters of a string with single backslashes Saving utf-8 texts with json.dumps as UTF8, not as \u escape sequence Properly escape a double quote in CSV How to Git stash pop specific stash in 1.8.3? In Java, should I escape a single quotation mark (') in String (double quoted)? How do I escape a single quote ( ' ) in JavaScript? Which characters need to be escaped when using Bash?

Examples related to git-stash

What is the intended use-case for git stash? How to recover stashed uncommitted changes How to Git stash pop specific stash in 1.8.3? Difference between git stash pop and git stash apply How to unstash only certain files? Stashing only staged changes in git - is it possible? How do I ignore an error on 'git pull' about my local changes would be overwritten by merge? git stash and git pull Stash just a single file git stash -> merge stashed change with current changes