How can I delete all of my Git stashes at once?
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 (...).
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
.
Use both of them with caution, it maybe is difficult to revert the once deleted stashes.
Here is the reference article.
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}:
while git stash drop 'stash@{20}'; do true; done
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} # Index will be shown after getting stash list
Note: git stash list
enables you to get index from stash area of git.