git stash 应用版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1910082/
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 07:30:31  来源:igfitidea点击:

git stash apply version

gitgit-stash

提问by Lee

I have 2 branches: master | design

我有 2 个分支: master | 设计

Working in design I did a stash and switched to master, made some adjustments. Switched back to design and did a stash applyonly to lose all my changes in the design branch.

在设计工作中,我做了一个 stash 并切换到 master,做了一些调整。切换回设计并做了一个stash apply只会丢失我在设计分支中的所有更改。

I am hoping all my work is within a stash as I have not cleared or removed these.

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

If I do a stash list I get 4 results:

如果我做一个藏匿清单,我会得到 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

If I try git stash apply f2c0c72I am getting an error:

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

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

How can I apply a specific stash?

如何应用特定的存储?

回答by araqnid

The keys into the stash are actually the stash@{n}items on the left. So try:

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

git stash apply stash@{0}

(note that in some shells you need to quote "stash@{0}", like zsh, fish and powershell).

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

Since version 2.11, it's pretty easy, you can use the N stack number instead of using stash@{n}. So now instead of using:

从 2.11 版开始,这很容易,您可以使用 N 堆栈号而不是使用stash@{n}. 所以现在而不是使用:

git stash apply "stash@{n}"

You can type:

您可以输入:

git stash apply n

To get list of stashes:

要获取隐藏列表:

git stash list

In fact stash@{0}is a revision in git that you can switch to... but git stash apply ...should figure out how to DTRT to apply it to your current location.

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

回答by Dan Loewenherz

To apply a stash and remove it from the stash list, run:

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

git stash pop stash@{n}

To apply a stash and keep it in the stash cache, run:

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

git stash apply stash@{n}

回答by Pau

Since version 2.11, it's pretty easy, you can use the N stack number instead of saying "stash@{n}". So now instead of using:

从 2.11 版开始,这很容易,您可以使用 N 堆栈号而不是说"stash@{n}"。所以现在而不是使用:

git stash apply "stash@{n}"

You can type:

您可以输入:

git stash apply n


For example, in your list:

例如,在您的列表中:

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

If you want to apply stash@{1}you could type:

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

git stash apply 1


Otherwise, you can use it even if you have some changes in your directory since 1.7.5.1, but you must be sure the stash won't overwrite your working directory changes if it does you'll get an error:

否则,即使自 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.

In versions prior to 1.7.5.1, it refused to work if there was a change in the working directory.

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



Git release notes:

Git 发行说明:

The user always has to say "stash@{$N}" when naming a single element in the default location of the stash, i.e. reflogs in refs/stash. The "git stash" command learned to accept "git stash apply 4" as a short-hand for "git stash apply stash@{4}"

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

git stash apply" used to refuse to work if there was any change in the working tree, even when the change did not overlap with the change the stash recorded

如果工作树中有任何更改,git stash apply”用于拒绝工作,即使更改与存储记录的更改不重叠

回答by jterry

If one is on a Windows machine and in PowerShell, one needs to quote the argument such as:

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

git stash apply "stash@{0}"

...or to apply the changes and remove from the stash:

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

git stash pop "stash@{0}"


Otherwise without the quotes you might get this error:

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

fatal: ambiguous argument 'stash@': unknown revision or path not in the working tree.

致命:模棱两可的参数“stash@”:未知的修订版或路径不在工作树中。

回答by panthari

git stash list

then select the stash to apply and use only number:

然后选择要应用的存储并仅使用数字:

git stash apply 1

回答by Harshavardhan reddy.

Git Stash list 

List will show all stashed items eg:stash@{0}:,stash@{1}:,..,stash@{n}:

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

Then select the number n which denotes stash@{n}:

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

git stash apply n 

for eg: git stash apply 1 will apply that particular stashed changes to the current branch