Home » Git » How to view a git stash list

How to view a git stash list

By Emily

If you have stashed some code changes in your git repo, and returned at a later date, you may find yourself wanting to list all of your git stashes. Before you use any stashed code you want to make sure you know exactly what you’ll be reintroducing to your code base. In this post I’ll show you how to view a full git stash list (‘git show stash list’ in other words) and how to view a specific git stash.

See the git stashes list

To view a current list of all your git stashes:

git stash list

You’ll see a list like this, showing one stash per line :

stash@{0}: WIP on main
stash@{1}: WIP on main
stash@{2}: WIP on main

How to view contents of one git stash in the list

Once you’ve seen you have more than one stash, you’ll probably want to preview the contents of one or more of them to work out which stash you want to apply to your current branch. To see the files in the most recent stash you would use:

git stash show

To view a specific git stash you would select it using its index. So for the second stash in the list shown above we would use this command:

git stash show stash@{1}

To view the diff in that stash, also called ‘git stash show diff‘:

git stash show -p stash@{1}

… and then you just change the index number to view the files in each stash in the list.

view contents of git stash

How to view the contents of a file in a stash

Using the example in the image above, maybe we want to see what changes were made in the file App.js that’s been stashed. In this case we’d use this command:

git diff HEAD stash@{{stash-number}} -- path-to/filename

which we would then use like this if we wanted to see the file App.js in the most recent stash:

git diff HEAD stash@{0} -- WebApplication1/Program.cs

.. and this would do the exact same thing because if we don’t specify the stash index then it will presume you want to use the most recent one:

git diff HEAD -- WebApplication1/Program.cs

Similarly if you wanted the file App.js from the second to most recent stash, then you would use the index 1 like this :

git diff HEAD stash@{1} -- WebApplication1/Program.cs

How to delete one of the stashes in the list

To get rid of the most recent stash:

git stash drop

To delete a specific stash from the list of stashes, you again use the index number of the stash you want to delete:

git stash drop stash@{1}

When the delete has succeeded you’ll see a confirmation message saying the stash has been deleted.

How to delete all of your git stash list

To delete all of the git stashes you use:

git stash clear

Summary

You now know how to view a list all of your git stashes. You also know how to see the contents of any of the stashes, and how to clear them, either individually or all at the same time. Read the official git documentation for all the details about which additional flags to use with the git stash command.