git stash应用版本

问题描述 投票:384回答:5

我有2个分支:master |设计

在设计工作中我做了一个藏匿并切换到主人,做了一些调整。切换回设计并做了一个stash apply只是为了失去我在设计分支中的所有变化。

我希望我的所有工作都在藏匿之内,因为我没有清除或删除这些。

如果我做一个藏匿列表,我得到4个结果:

stash@{0}: WIP on design: f2c0c72... Adjust Password Recover Email
stash@{1}: WIP on design: f2c0c72... Adjust Password Recover Email
stash@{2}: WIP on design: eb65635... Email Adjust
stash@{3}: WIP on design: eb65635... Email Adjust

如果我尝试git stash apply f2c0c72我收到一个错误:

fatal: Needed a single revision
f2c0c72: no valid stashed state found

我该如何申请特定藏匿?

git git-stash
5个回答
628
投票

进入藏匿处的钥匙实际上是左侧的stash@{n}物品。所以尝试:

git stash apply stash@{0}

(请注意,在某些shell中,您需要引用"stash@{0}",如zsh,fish和powershell)。

从版本2.11开始,它非常简单,您可以使用N堆栈编号而不是使用stash@{n}。所以现在而不是使用:

git stash apply "stash@{n}"

你可以输入:

git stash apply n

要获取藏匿列表:

git stash list

实际上stash@{0}是git中的一个修订版,你可以切换到......但git stash apply ...应该弄清楚如何将DTRT应用到你当前的位置。


221
投票

要应用存储并将其从存储列表中删除,请运行:

git stash pop stash@{n}

要应用存储并将其保存在存储缓存中,请运行:

git stash apply stash@{n}

43
投票

从版本2.11开始,它非常简单,您可以使用N堆栈编号而不是说"stash@{n}"。所以现在而不是使用:

git stash apply "stash@{n}"

你可以输入:

git stash apply n

例如,在您的列表中:

stash@{0}: WIP on design: f2c0c72... Adjust Password Recover Email
stash@{1}: WIP on design: f2c0c72... Adjust Password Recover Email
stash@{2}: WIP on design: eb65635... Email Adjust
stash@{3}: WIP on design: eb65635... Email Adjust

如果你想申请stash@{1}你可以输入:

git stash apply 1

否则,即使您在1.7.5.1之后对目录进行了一些更改,也可以使用它,但是您必须确保存储不会覆盖您的工作目录更改,否则会出现错误:

error: Your local changes to the following files would be overwritten by merge:
        file
Please commit your changes or stash them before you merge.

在1.7.5.1之前的版本中,如果工作目录发生更改,则拒绝工作。


Git发行说明:

当在存储的默认位置命名单个元素时,用户总是必须说“存储@ {$ N}”,即refs / stash中的reflogs。 “git stash”命令学会接受“git stash apply 4”作为“git stash apply stash @ {4}”的简写

git stash apply“用于在工作树中有任何变化时拒绝工作,即使更改与存储记录的更改不重叠


40
投票

如果一个在Windows机器和PowerShell中,则需要引用如下参数:

git stash apply "stash@{0}"

...或者应用更改并从存储中删除:

git stash pop "stash@{0}"

否则,如果没有引号,您可能会收到此错误:

致命的:模糊的论点'stash @':未知的修订或路径不在工作树中。


2
投票
git stash apply n

然后选择要存储的存储

git stash apply 1

0
投票
Git Stash list 

列表将显示所有藏匿的项目,例如:stash @ {0} :, stash @ {1}:,..,stash @ {n}:

然后选择表示存储@ {n}的数字n:

git stash apply n 

for eg: git stash apply 1 will apply that particular stashed changes to the current branch
© www.soinside.com 2019 - 2024. All rights reserved.