How can I delete all of my Git stashes at once?
Specifically I mean, with typing in one command.
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:
$ git stash drop <stash_id>
. $ git stash clear
.Use both of them with caution, it maybe is difficult to revert the once deleted stashes.
Here is the reference article.
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.
To delete all stashes older than 40 days, use:
git reflog expire --expire-unreachable=40.days refs/stash
Add --dry-run
to see which stashes are deleted.
See https://stackoverflow.com/a/44829516/946850 for an explanation and much more detail.
if you want to remove the latest stash or at any particular 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
If you just want to clear the latest stash or even you created a stash with git stash create then you should simply use
git stash drop
but if you want to clear all the git stashes of the current git repository then you can use
git stash clear
WARNING: Those states will then be subject to pruning(knock off), and maybe impossible to recover