如何一次删除所有 Git 存储?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11369375/
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
How can I delete all of my Git stashes at once?
提问by Rebekah Waterbury
回答by Tadeck
The following command deletes all your stashes:
以下命令将删除您的所有存储:
git stash clear
From the git documentation:
从git 文档:
clear
Remove all the stashed states.
IMPORTANT WARNING:Those states will then be subject to pruning, and may be impossible to recover (...).
clear
删除所有隐藏的状态。
重要警告:这些状态将受到修剪,并且可能无法恢复(...)。
回答by Nesha Zoric
There are two ways to delete a stash:
有两种方法可以删除存储:
- If you no longer need a particular stash, you can delete it with:
$ git stash drop <stash_id>
. - You can delete all of your stashes from the repo with:
$ git stash clear
.
- 如果您不再需要某个特定的藏匿处,可以使用以下命令将其删除:
$ git stash drop <stash_id>
。 - 您可以使用以下命令从 repo 中删除所有 stash:
$ git stash clear
。
Use both of them with caution, it maybe is difficult to revert the once deleted stashes.
谨慎使用它们,可能很难恢复曾经删除的存储。
Here is the reference article.
这是参考文章。
回答by Vikrant Kashyap
this command enables you to look all stashed changes.
此命令使您能够查看所有隐藏的更改。
git stash list
Here is the following command use it to clear all of your stashed Changes
这是以下命令,使用它来清除所有隐藏的更改
git stash clear
Now if you want to delete one of the stashed changes from stash area
现在,如果您想从存储区域中删除隐藏的更改之一
git stash drop stash@{index} // here index will be shown after getting stash list.
Note :
git stash list
enables you to get index from stash area of git.
注意:
git stash list
使您能够从 git 的存储区域获取索引。
回答by warp
I wanted to keep a few recent stashes, but delete everything else.
我想保留一些最近的藏匿处,但删除其他所有内容。
Because all stashes get renumbered when you drop one, this is actually easy to do with while. To delete all stashes older than stash@{19}:
因为当你放下一个时,所有的藏匿处都会重新编号,这实际上很容易做到。要删除所有早于 stash@{19} 的 stash:
while git stash drop 'stash@{20}'; do true; done
回答by Shivam Bharadwaj
if you want to remove the latest stash or at any particular index-
如果您想删除最新的存储或任何特定索引-
git stash drop type_your_index
git stash drop type_your_index
> git stash list
stash@{0}: abc
stash@{1}: xyz
stash@{1}: pqr
> git stash drop 0
Dropped refs/stash@{0}
> git stash list
stash@{0}: xyz
stash@{1}: pqr
if you want to remove all the stash at once-
如果你想一次删除所有的藏品-
> git stash clear
>
> git stash list
>
Warning: Once done you can not revert back your stash
警告:一旦完成,您将无法恢复您的存储
回答by Bala Krishnan
I had another requirement like only few stash have to be removed, below code would be helpful in that case.
我还有另一个要求,比如只需要删除很少的藏匿处,在这种情况下,下面的代码会有所帮助。
#!/bin/sh
for i in `seq 5 8`
do
git stash drop stash@{$i}
done
/* will delete from 5 to 8 index*/
/* 将删除从 5 到 8 的索引*/
回答by krlmlr
To delete all stashes older than 40 days, use:
要删除超过 40 天的所有存储,请使用:
git reflog expire --expire-unreachable=40.days refs/stash
Add --dry-run
to see which stashes are deleted.
添加--dry-run
以查看删除了哪些存储。
See https://stackoverflow.com/a/44829516/946850for an explanation and much more detail.
有关解释和更多详细信息,请参阅https://stackoverflow.com/a/44829516/946850。