【问题标题】:How to Git stash pop specific stash in 1.8.3?如何在 1.8.3 中 Git stash pop 特定的存储?
【发布时间】:2013-07-03 17:12:17
【问题描述】:

我刚刚升级了 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

标签: git escaping git-stash


【解决方案1】:
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 一个特定的存储,并且这个命令applys 存储而不是弹出它。不同之处在于 pop 既将存储应用于代码,又删除了存储本身。
  • 不适合我。收到错误“未知选项:-encodedCommand”
  • 请更新你的答案,现在是git stash apply n
【解决方案2】:

你需要转义大括号:

git stash pop stash@\{1\}

【讨论】:

  • 或者只是放入双引号,例如git stash pop "stash@{1}"
【解决方案3】:

如果您想确保不必处理 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 年来到这里的人来说,这可能是最相关的答案。
【解决方案4】:

在 Windows Powershell 上我运行这个:

git stash apply "stash@{1}"

【讨论】:

  • 也适用于 ubuntu linux
  • 也可以在 Mac OS X 上运行。我更喜欢这个而不是转义单个字符。
【解决方案5】:

正如 Robert 指出的,引号可能对你有用:

git stash pop stash@"{1}"

【讨论】:

    【解决方案6】:

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

    git stash pop "stash@{0}"
    

    【讨论】:

      【解决方案7】:

      版本 2.11+ 使用以下内容:

      git stash list
      
      git stash apply n
      

      n 是数字 stash@{12}

      【讨论】:

        【解决方案8】:

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

        git stash pop --index 1
        

        【讨论】:

        • 它不起作用.. $ git stash pop --index 1 致命:不明确的参数'1':未知的修订或路径不在工作树中。使用 '--' 将路径与修订分开,如下所示:'git [...] -- [...]'
        • 弹出隐藏的警告
        【解决方案9】:

        首先查看列表:-

        git stash list
        

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

        git stash pop stash@{index_number}
        

        例如:

        git stash pop stash@{1}
        

        【讨论】:

          【解决方案10】:

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

          【讨论】:

            猜你喜欢
            • 2012-12-25
            • 2012-01-20
            • 2017-11-25
            • 2013-02-23
            • 1970-01-01
            • 2023-03-11
            • 1970-01-01
            • 2018-10-02
            相关资源
            最近更新 更多