How to View Git Stash Contents Without Applying
Learn to view Git stash contents without applying using git stash list for inventory, git stash show for summaries, and git stash show -p for full diffs. Safe inspection of changes, untracked files, and advanced tips for Git workflows.
How do I view the contents of a Git stash without applying it?
To view the contents of a Git stash without applying it, start by listing all stashes with git stash list—it shows indexes like stash@{0}. Then use git stash show for a quick summary of changes in the top stash, or git stash show -p stash@{n} to see the full diff patch without touching your working directory. This keeps your code safe while letting you inspect exactly what you stashed, whether it’s file changes or even untracked files.
Contents
- What is Git Stash?
- List All Stashes
- View Stash Summary
- See Full Patch Without Applying
- Handle Specific Stashes and Untracked Files
- Advanced Tips and Tricks
- Sources
- Conclusion
What is Git Stash?
Git stash is your quick-save button in version control. Picture this: you’re knee-deep in a feature branch, but a urgent bug fix lands on main. Instead of committing half-baked code or creating a messy branch, git stash shelves your changes temporarily. It captures your working directory and index state, pushing it onto a stack.
But what if weeks pass and you forget what’s inside? Applying blindly with git stash pop could clash with current code. That’s where viewing comes in—no apply needed. Commands like git stash show let you peek risk-free. According to the official Git documentation, stashes are stored as commits, so you get diff-like inspections.
Why bother? It saves headaches. Ever lost track of stashed experiments? This workflow keeps you productive without the “oops” moments.
List All Stashes
First things first: know what’s available. Run this:
git stash list
Output might look like:
stash@{0}: WIP on main: 3f2e1a2 Temp work
stash@{1}: WIP on feature: abc1234 Login fixes
Each entry has an index (stash@{0} is newest). This command, straight from GeeksforGeeks, gives descriptions based on your branch and commit at stash time.
Pro tip: Pipe to grep for filtering, like git stash list | grep "login". Or use git stash list --stat for mini-summaries. No more digging blindly—it’s instant inventory.
Short and sweet. But listing alone doesn’t reveal files or lines changed. Ready for details?
View Stash Summary
Now, inspect the top stash (stash@{0}) without the full commit:
git stash show
Expect something like:
file1.txt | 10 ++++++++++
1 file changed, 10 insertions(+)
This diffstat shows files affected, insertions (+), deletions (-). Target a specific one? git stash show stash@{1}.
Codippa explains it lists files and change counts perfectly for quick scans. “Is it just a typo fix? Or major rewrites?” Answer in seconds.
What if untracked files snuck in? Add -u: git stash show -u. Config tweak: git config stash.showIncludeUntracked true for defaults, per official docs.
Simple. Effective. But summaries tease—want the actual code diffs?
See Full Patch Without Applying
Here’s the powerhouse: full line-by-line view.
git stash show -p
Or for stash@{1}:
git stash show -p stash@{1}
Sample output:
diff --git a/file.txt b/file.txt
index abcdef1..1234567 100644
--- a/file.txt
+++ b/file.txt
@@ -1,4 +1,5 @@
This is line 1
This is line 2
+This is a new line added in the stash
This is line 3
Plus signs for adds, minuses for deletes. Stack Overflow users swear by this—it’s the go-to for “what’s in there?” without risk.
Pipe to less for scrolling: git stash show -p | less. Or script a viewer:
git stash list | awk -F: '{ print "\n\n"; print $0; system("git stash show -p " $1); }' | less
From TheServerSide, endless log-like options enhance it. Boom—full transparency.
Handle Specific Stashes and Untracked Files
Stashes pile up? Indexes shift with pops or drops. Always list first.
For untracked files (if you stashed with git stash -u):
git stash show -p -u stash@{0}
Opensource.com covers this well—shows modified files like src/index.html with exact hunks.
W3Schools demo:
modified: src/index.html
Target one file? Tricky, but git stash show -p stash@{0} -- path/to/file.txt works.
Edge case: Empty stash? It warns. Stale refs? git fsck cleans. These tweaks handle real-world mess.
Advanced Tips and Tricks
Customize views via config:
git config stash.showPatch true
git config stash.showStat false
Now git stash show defaults to patch. From official docs.
View all stashes’ patches? Loop: for i in $(git stash list --format="%gd"); do git stash show -p $i; done.
Compare stashes: git stash show -p stash@{0} | diff -u <(git stash show -p stash@{1}) -.
Stash naming? git stash push -m "WIP login". List shows it clearly.
Troubleshoot: git stash clear drops all—view first! Integrates with GUI tools like GitKraken too.
Master this, and stashes become allies, not mysteries.
Sources
- How to List and Show the Git Stash History? - GeeksforGeeks
- Git - View Files in stash & their contents without applying - Codippa
- Git - git-stash Documentation
- See what’s in a stash without applying it - Stack Overflow
- How to list and show the git stash history - TheServerSide
- A practical guide to using the git stash command - Opensource.com
- Git Stash - W3Schools
Conclusion
Viewing Git stash contents boils down to git stash list for inventory, git stash show for summaries, and git stash show -p for full diffs—zero apply risk. Mix in -u for untracked files or configs for personalization, and you’re set for any workflow snag. Next time a stash haunts you, peek first; it’ll save your day and keep commits clean.