如何在 1.8.3 中 Git stash pop 特定的 stash?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17454235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:29:47  来源:igfitidea点击:

How to Git stash pop specific stash in 1.8.3?

gitescapinggit-stash

提问by Jesse Atkinson

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

我刚刚升级了 Git。我使用的是 Git 版本 1.8.3。

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

今天早上,我试图在堆栈中取出一个更改 1。

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

我跑了git stash pop stash@{1},得到了这个错误。

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

致命:模棱两可的参数“stash@1”:未知的修订版或路径不在工作树中。使用“--”将路径与修订分开,如下所示:“git [...] -- [...]”

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

我已经尝试了大约 20 多种变体以及使用apply而不是pop没有成功。有什么变化?还有其他人遇到这个吗?

回答by Bob Gilmore

git stash apply n

works as of git version 2.11

从 git 版本 2.11 开始工作

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

原始答案,可能有助于调试涉及 shell 转义的旧语法的问题:

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

如前所述,花括号可能需要转义或引用,具体取决于您的操作系统、shell 等。

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.

请参阅“ stash@{1} is ambiguous?”以获取可能出错的一些详细提示,以及如何在各种 shell 和平台中解决此问题。

git stash list
git stash apply stash@{n}

git stash apply version

git stash 应用版本

回答by Vasiliy

You need to escape the braces:

您需要转义大括号:

git stash pop stash@\{1\}

回答by VonC

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

如果您想确保不必处理语法的引号stash@{x},请使用 Git 2.11(2016 年第 4 季度)

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

请参阅Aaron M Watson ( )提交的 a56c8f5(2016 年 10 月 24 日(由Junio C Hamano合并-- --提交 9fa1f90 中,2016 年 10 月 31 日)watsona4
gitster

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.

stash: 只允许索引引用隐藏

而不是stash@{n}明确引用“ ”,而是可以简单地引用为“ n”。
大多数用户仅通过它们在 stash 堆栈中的位置(我在这里称为“索引”)来引用 stash。

典型 stash ( stash@{n})的语法有点烦人且容易忘记,有时很难在脚本中正确转义

因此,通过简单地引用索引来处理存储的能力是可取的。

So:

所以:

git stash drop 1
git stash pop 1
git stash apply 1
git stash show 1

回答by Robert Brooker

On Windows Powershell I run this:

在 Windows Powershell 上我运行这个:

git stash apply "stash@{1}"

回答by owenmck

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

正如罗伯特指出的,引号可能对你有用:

git stash pop stash@"{1}"

回答by Kenan

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

如果上述方法均无效,则存储本身周围的引号可能对您有用:

git stash pop "stash@{0}"

回答by markg

I have 2.22 installed and this worked..

我安装了 2.22 并且这有效..

git stash pop --index 1

回答by manish kumar

Version 2.11+ use the following:

版本 2.11+ 使用以下内容:

git stash list

git stash apply n

n is the number stash@{12}

n 是数量stash@{12}

回答by Jabbi Syed

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}