The Hook (The "Byte-Sized" Intro)
If you stash and forget, you'll end up with a pile of mystery boxes. git stash list shows every stash you've saved — with index, branch, and message. But that's just the start. You can also diff a stash, show its contents, and check what files it touched — all without applying it. Knowledge is power; inspect before you pop.
📖 What is Listing Stashes?
Listing stashes means viewing all saved stash entries and inspecting their contents. Each entry sits on a stack and can be examined individually.
Conceptual Clarity
Reading stash list output:
stash@{0}: On feature/login: WIP: add validation
stash@{1}: On main: WIP: fix header styling
stash@{2}: WIP on main: a1b2c3d Initial commit
| Part | Meaning |
|---|---|
stash@{0} | Index — 0 is the most recent |
On feature/login: | Branch the stash was created on |
WIP: add validation | Your message (or auto-generated label) |
Inspection commands:
| Command | What It Shows |
|---|---|
git stash list | All stash entries (index, branch, message) |
git stash show | Files changed in the latest stash (summary) |
git stash show -p | Full diff of the latest stash (patch) |
git stash show stash@{2} | Summary for a specific stash |
git stash show -p stash@{2} | Full diff for a specific stash |
Real-Life Analogy
git stash list is like checking the label on each storage box on a shelf. git stash show is like opening a box to peek inside without taking anything out.
Visual Architecture
Why It Matters
- Discovery: Find that stash you created 3 days ago.
- Verification: See exactly what a stash contains before applying it.
- Safety: Inspect contents to make sure you're applying the right stash.
- Cleanup: Identify old, no-longer-needed stashes to drop.
Code
# ─── List all stashes ───
git stash list
# Output:
# stash@{0}: On feature/login: WIP: add validation
# stash@{1}: On main: WIP: fix header styling
# ─── Show files changed in the latest stash ───
git stash show
# Output:
# src/login.js | 12 +++++++++---
# src/auth.js | 5 +++++
# 2 files changed, 14 insertions(+), 3 deletions(-)
# ─── Show full diff (patch) of the latest stash ───
git stash show -p
# Shows the actual line-by-line changes
# ─── Inspect a specific stash ───
git stash show stash@{1}
git stash show -p stash@{1}
# ─── Show stash with stat + diff combined ───
git stash show --stat -p stash@{0}Key Takeaways
git stash listshows all stashes with index, branch, and message.git stash showgives a summary; add-pfor the full diff.- Always inspect a stash before applying it to avoid surprises.
- Indexes start at
0(most recent) and count up.
Interview Prep
-
Q: How do you see what changes are in a specific stash? A: Use
git stash show stash@{N}for a summary of files changed, orgit stash show -p stash@{N}for the full line-by-line diff. -
Q: What does
stash@{0}refer to? A: The most recently created stash entry. Stashes work as a stack — the newest is always at index 0, and older stashes shift to higher indexes. -
Q: Can you view a stash's changes without applying it? A: Yes.
git stash show -pdisplays the full diff without modifying your working tree. This lets you verify the contents before deciding to apply or drop the stash.