Git by Example: Stash Listing
Learn how to view and manage your stashed changes. This example explains the stash stack, how to list entries, and how to inspect the contents of a specific stash.
Code
# 1. Stash some changes
git stash push -m "Work on login feature"
# 2. List all stashes
git stash list
# Output:
# stash@{0}: On main: Work on login feature
# stash@{1}: WIP on main: 1a2b3c Initial commit
# 3. Show details of the most recent stash
git stash show -p stash@{0}
# 4. Show details of an older stash
git stash show stash@{1}
# 5. Clear the stash list (delete all stashes)
git stash clearExplanation
The git stash list command is your window into the "stack" of stashed changes. Git stores stashes in a Last-In-First-Out (LIFO) stack, meaning the most recent stash is always at the top with the index stash@{0}. As you add more stashes, older ones are pushed down the list and their indices increment (e.g., stash@{1}, stash@{2}).
By default, a stash is given a generic message like "WIP on branch-name...". However, it is highly recommended to provide a custom message using git stash push -m "message". This makes the output of git stash list much more useful, allowing you to quickly identify what work is contained in each entry without having to inspect it.
To see what's actually inside a stash, you can use git stash show. By default, this gives you a summary of changed files. Adding the -p (patch) flag shows the actual code differences (diff), similar to git diff. You can target any specific stash by referring to its index, like stash@{2}.
- Displays stashes in a LIFO stack
stash@{0}is always the most recent- Use custom messages for better organization
- Inspect contents with
git stash show -p

