如何删除使用 git stash create 创建的存储?

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

How to delete a stash created with git stash create?

git

提问by Paul Wagland

Git stash seems to do a lot of what I want, except that it is a little hard to script, as the if you have no changes, then git stash; git stash popwill do something different than if you do have changes in your repository.

Git stash 似乎做了很多我想做的事情,除了编写脚本有点困难,因为如果您没有更改,那么git stash; git stash pop与您的存储库中有更改时会做一些不同的事情。

It appears that git stash createis the answer to that problem, and everything works, except for one thing… I can't get rid of the created stash. Is there any way to get rid of the stash?

看来这git stash create就是这个问题的答案,一切正常,除了一件事......我无法摆脱创建的藏匿处。有没有办法摆脱藏匿?

To make it 100% clear what I am doing:

为了使其 100% 清楚我在做什么:

Create the stash:

创建存储:

~/tmp/a(master) $ git stash create 
60629375d0eb12348f9d31933dd348ad0f038435
~/tmp/a(master) $ git st
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#
~/tmp/a(master) $ git reset --hard
HEAD is now at 555d572 log message

Use the stash:

使用藏匿处:

~/tmp/a(master) $ git apply 60629375d0eb12348f9d31933dd348ad0f038435
fatal: can't open patch '60629375d0eb12348f9d31933dd348ad0f038435': No such file or directory
~/tmp/a(master) $ git stash apply 60629375d0eb12348f9d31933dd348ad0f038435
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#

Delete the stash: (except that this last bit doesn't work)

删除存储:(除了最后一点不起作用)

~/tmp/a(master) $ git stash drop !$
git stash drop 60629375d0eb12348f9d31933dd348ad0f038435
'60629375d0eb12348f9d31933dd348ad0f038435' is not a stash reference

采纳答案by dahlbyk

To delete a normal stash created with git stash, you want git stash dropor git stash drop stash@{n}. See below for more details.

要删除使用 创建的普通存储git stash,您需要git stash dropgit stash drop stash@{n}。请参阅下面的更多细节。



You don't need to delete a stash created with git stash create. From the docs:

您不需要删除使用git stash create. 从文档:

Create a stash entry (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. This is intended to be useful for scripts. It is probably not the command you want to use; see "save" above.

创建一个存储条目(这是一个常规提交对象)并返回其对象名称,而不将其存储在 ref 命名空间中的任何位置。这旨在对脚本有用。它可能不是您要使用的命令;请参阅上面的“保存”。

Since nothing references the stash commit, it will get garbage collected eventually.

由于没有任何内容引用存储提交,因此最终会被垃圾收集。



A stash created with git stashor git stash saveis saved to refs/stash, and can be deleted with git stash drop. As with all Git objects, the actual stash contents aren't deleted from your computer until a gcprunes those objects after they expire (default is 2 weeks later).

使用git stash或创建的存储git stash save保存到refs/stash,并且可以使用 删除git stash drop。与所有 Git 对象一样,实际存储内容不会从您的计算机中删除,直到gc在它们过期后修剪这些对象(默认为 2 周后)。

Older stashes are saved in the refs/stashreflog(try cat .git/logs/refs/stash), and can be deleted with git stash drop stash@{n}, where nis the number shown by git stash list.

较旧的 stash 保存在refs/stashreflog(try cat .git/logs/refs/stash) 中,可以使用 删除git stash drop stash@{n},其中n是 显示的数字git stash list

回答by CB Bailey

git stash droptakes no parameter - which drops the top stash - or a stash reference which looks like: stash@{n}which nnominates which stash to drop. You can't pass a commit id to git stash drop.

git stash drop不接受任何参数 - 丢弃顶部存储 - 或者看起来像这样的存储引用:stash@{n}n指定要丢弃的存储。您不能将提交 ID 传递给git stash drop.

git stash drop            # drop top hash, stash@{0}
git stash drop stash@{n}  # drop specific stash - see git stash list

Dropping a stash will changethe stash@{n}designations of all stashes further down the stack.

丢弃一个储藏室将更改stash@{n}堆栈更下方的所有储藏室的名称。

I'm not sure why you think need to drop a stash because if you are using stash createa stash entry isn't created for your "stash" so there isn't anything to drop.

我不知道为什么你认为需要删除一个藏匿处,因为如果你正在使用stash create一个藏匿处条目不是为你的“藏匿处”创建的,所以没有任何东西可以放下。

回答by Felipe Pereira

If you are 100% sure that you have just one stash or you want to delete all stashes(make a git stash listto be 107% sure), you can do a:

如果您 100% 确定您只有一个 stash或者您想删除所有stash (使 agit stash list成为 107% 确定),您可以执行以下操作:

git stash clear

..and forget about them (it deletes all stashes).

..并忘记它们(它会删除所有隐藏)。

Note: Added this answer for those who ended up here looking for a way to clear them all (like me).

注意:为那些最终在这里寻找清除它们的方法的人(像我一样)添加了这个答案。

回答by Jorge

From git doc: http://git-scm.com/docs/git-stash

来自 git 文档:http: //git-scm.com/docs/git-stash

drop [-q|--quiet] []

drop [-q|--quiet] []

Remove a single stashed state from the stash list. When no is given, it removes the latest one. i.e. stash@{0}, otherwise must be a valid stash log reference of the form stash@{}.

从存储列表中删除单个隐藏状态。如果没有给出,它会删除最新的。即stash@{0},否则必须是 stash@{} 形式的有效存储日志引用。

example:

例子:

git stash drop stash@{5}

This would delete the stash entry 5. To see all the list of stashes:

这将删除 stash 条目 5. 要查看所有 stash 列表:

git stash list

回答by ShalomSam

You should be using

你应该使用

git stash save

and not

并不是

git stash create

because this creates a stash (which is a regular commit object) and return its object name, without storing it anywherein the ref namespace. Hence won't be accessible with stash apply.

因为这会创建一个存储(这是一个常规提交对象)并返回其对象名称,而不会将存储在 ref 命名空间中的任何位置。因此将无法通过 stash apply 访问。

Use git stash save "some comment"is used when you have unstaged changes you wanna replicate/move onto another branch

git stash save "some comment"当您有要复制/移动到另一个分支的未暂存更改时使用

Use git stash apply stash@{0}(assuming your saved stash index is 0) when you want your saved(stashed) changes to reflect on your current branch

git stash apply stash@{0}当您希望保存的(隐藏的)更改反映在当前分支上时使用(假设您保存的存储索引为 0)

you can always use git stash listto check all you stash indexes

你总是可以git stash list用来检查所有你藏匿的索引

and use git stash drop stash@{0}(assuming your saved stash index is 0 and you wanna delete it) to delete a particular stash.

并使用git stash drop stash@{0}(假设您保存的存储索引为 0 并且您想删除它)删除特定的存储。

回答by MonTea

It also works

它也有效

git stash drop <index>

like

喜欢

git stash drop 5

回答by Longalei

The Document is here (in Chinese)please click.

文档在这里(中文)请点击。

you can use

您可以使用

git stash list

git stash drop stash@{0}

git 存储列表

git stash drop stash@{0}

enter image description here

在此处输入图片说明

回答by Bilal Yaqoob

git stash           // create stash,
git stash push -m "message" // create stash with msg,
git stash apply         // to apply stash,
git stash apply indexno // to apply  specific stash, 
git stash list          //list stash,
git stash drop indexno      //to delete stash,
git stash pop indexno,
stash pop = stash drop + stash apply
git stash clear         //clear all your local stashed code