How to Delete Stash Record in Git

Ashok Chapagai Feb 02, 2024
How to Delete Stash Record in Git

In Git, you can keep hold of changes or store them by stashing them, which is a relatively straightforward command.

To stash changes, you have to use git stash to stash changes. Then to list the changes you have stashed, use the git stash list. To pop the topmost change, you can use git stash pop, or to pop specific change, you can use the number the stashed change refers to as git stash pop 1.

Delete Top Stash (First in the List) or a Particular Stash

The more you stash changes, the taller the stashed tree becomes since the stashed record is placed on top of your recent stash. Hence, the command git stash drop will drop the topmost stash or the most recent stashed record.

But, that might seldom be the case, and you might want to delete other stashed records. You can use the commands below to do that.

git stash list

To list the stashed records which look similar to this.

stash@{0}: WIP on master: acf341a Create index.js
stash@{1}: WIP on master: cdf45a Revert "all js files"
stash@{2}: WIP on master: afca12 Add style.css

Now that you see the stashed records and want to delete stash@{2}, you can use this code.

git stash drop 2
# Or you can also use,
git stash drop stash@{2}

The command above will drop the last stash record. If you drop other records, for example, stash@{1}, then the current stash@{2} will be indexed as stash@{1}.

However, if you want to delete all stashes, you can use the code below, which deletes all the stashed records.

git stash drop
Ashok Chapagai avatar Ashok Chapagai avatar

Ashok is an avid learner and senior software engineer with a keen interest in cyber security. He loves articulating his experience with words to wider audience.

LinkedIn GitHub

Related Article - Git Stash