如何一次删除所有Git stashes?

本文翻译自:How can I delete all of my Git stashes at once?

How can I delete all of my Git stashes at once? 如何一次删除所有Git stashes?

Specifically I mean, with typing in one command. 具体来说,我的意思是,输入一个命令。


#1楼

参考:https://stackoom.com/question/lhh1/如何一次删除所有Git-stashes


#2楼

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 (...). 重要警告:这些州将进行修剪,可能无法恢复(......)。


#3楼

There are two ways to delete a stash: 删除存储有两种方法:

  1. If you no longer need a particular stash, you can delete it with: $ git stash drop <stash_id> . 如果您不再需要特定存储,可以使用以下命令将其删除: $ git stash drop <stash_id>
  2. You can delete all of your stashes from the repo with: $ git stash clear . 您可以使用以下命令从回购中删除所有$ git stash clear$ git stash clear

Use both of them with caution, it maybe is difficult to revert the once deleted stashes. 谨慎使用它们,可能很难恢复曾经删除过的藏匿处。

Here is the reference article . 这是参考文章


#4楼

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的stash区域获取索引。


#5楼

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个索引* /


#6楼

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}更旧的所有藏匿处:

while git stash drop 'stash@{20}'; do true; done
发布了0 篇原创文章 · 获赞 136 · 访问量 83万+

猜你喜欢

转载自blog.csdn.net/xfxf996/article/details/105248816