Advertisement
Advertisement


How can I delete all of my Git stashes at once?


Question

How can I delete all of my Git stashes at once?

Specifically I mean, with typing in one command.

2013/10/29
1
1452
10/29/2013 8:56:08 PM

Accepted Answer

The following command deletes all your stashes:

git stash clear

From the git documentation:

clear

Remove all the stashed states.

IMPORTANT WARNING: Those states will then be subject to pruning, and may be impossible to recover (...).

2020/06/20
2536
6/20/2020 9:12:55 AM

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>.
  2. You can delete all of your stashes from the repo with: $ git stash clear.

Use both of them with caution, it maybe is difficult to revert the once deleted stashes.

Here is the reference article.

2019/01/09

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 [email protected]{index}   // here index will be shown after getting stash list.

Note : git stash list enables you to get index from stash area of git.

2019/03/27

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 [email protected]{19}:

while git stash drop '[email protected]{20}'; do true; done
2019/08/21

if you want to remove the latest stash or at any particular index -

git stash drop type_your_index

> git stash list

  [email protected]{0}: abc
  [email protected]{1}: xyz
  [email protected]{1}: pqr

> git stash drop 0

  Dropped refs/[email protected]{0}

> git stash list

  [email protected]{0}: xyz
  [email protected]{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

2020/05/18

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 [email protected]{$i}
done

/* will delete from 5 to 8 index*/

2019/03/29