How to git stash pop specific stash in 1.8.3?

2019-03-07 13:38发布

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 <command> [<revision>...] -- [<file>...]'

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?

7条回答
我想做一个坏孩纸
2楼-- · 2019-03-07 13:41

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

查看更多
仙女界的扛把子
3楼-- · 2019-03-07 13:46

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

git stash pop stash@"{1}"
查看更多
老娘就宠你
4楼-- · 2019-03-07 13:47

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
查看更多
趁早两清
5楼-- · 2019-03-07 13:47

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

git stash pop "stash@{0}"
查看更多
等我变得足够好
6楼-- · 2019-03-07 13:53

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}
查看更多
混吃等死
7楼-- · 2019-03-07 13:59

On Windows Powershell I run this:

git stash apply "stash@{1}"
查看更多
登录 后发表回答