ChatGPT解决这个技术问题 Extra ChatGPT

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

我刚刚升级了 Git。我在 Git 版本 1.8.3 上。

今天早上,我试图在堆栈深处解开更改 1。

我运行 git stash pop stash@{1} 并收到此错误。

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

我已经尝试了大约 20 多种变体,并使用 apply 而不是 pop,但均未成功。有什么改变?还有人遇到这种情况吗?

您是否尝试转义 {}?
对于 Git 2.11(2016 年第四季度),您现在可以使用 git stash pop 1:请参阅 my answer below

B
Bob Gilmore
git stash apply n

从 git 版本 2.11 开始工作

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

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

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

git stash list
git stash apply stash@{n}

git stash apply version


我对这个答案的唯一不满是问题询问如何pop特定的存储并且此命令apply是存储而不是弹出它。不同之处在于 pop 既将存储应用于代码,又删除了存储本身。
不为我工作。收到错误“未知选项:-encodedCommand”
请更新您的答案,现在是git stash apply n
i
isherwood

您需要转义大括号:

git stash pop stash@\{1\}

或者只是放入双引号,例如 git stash pop "stash@{1}"
C
Community

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

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

stash:允许仅通过索引引用 stash 而不是显式引用“stash@{n}”,而是可以简单地引用为“n”。大多数用户只通过他们在存储堆栈中的位置来引用存储(我在这里称为“索引”)。典型的 stash (stash@{n}) 的语法有点烦人且容易忘记,有时很难在脚本中正确转义。因此,通过简单地引用索引来处理存储的能力是可取的。

所以:

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

谢谢!对于 2019 年来到这里的人来说,这可能是最相关的答案。
R
Robert Brooker

更新

从 git 2.11 只需使用数字:

git stash apply 1

原件

在 Windows Powershell 我运行这个:

git stash apply "stash@{1}"

也适用于 ubuntu linux
也适用于 Mac OS X。我喜欢这个比转义单个字符更好。
o
owenmck

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

git stash pop stash@"{1}"

K
Kenan

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

git stash pop "stash@{0}"

m
manish kumar

版本 2.11+ 使用以下内容:

git stash list

git stash apply n

n 是数字 stash@{12}


m
markg

我安装了 2.22 并且这工作..

git stash pop --index 1

它不起作用.. $ git stash pop --index 1 fatal: ambiguous argument '1': 未知的修订或路径不在工作树中。使用 '--' 将路径与修订分开,如下所示:'git [...] -- [...]'
弹出你的藏匿处的警告
V
Vaibhav Vishal

首先检查列表:-

git stash list

复制要从存储列表中弹出的索引

git stash pop stash@{index_number}

例如。:

git stash pop stash@{1}

P
PaulBunion

我在这个列表中多次看到这个答案,但为了明确起见,至少从 git 版本 2.33.0,git stash pop stash@{n} is valid 开始。无需逃避。