0
0
GitHow-ToBeginner · 3 min read

How to Show Stash Contents in Git: Commands and Examples

Use git stash show to see a summary of the changes in the latest stash. To view detailed changes, use git stash show -p which shows the full diff of the stash contents.
📐

Syntax

The basic command to view stash contents is git stash show [options] [].

  • git stash show: Shows a summary of changes in the latest stash.
  • -p or --patch: Shows the full diff of the stash contents.
  • <stash>: Optional stash reference like stash@{0} to specify which stash to show.
bash
git stash show [options] [<stash>]

# Examples:
git stash show

git stash show -p

git stash show stash@{1} -p
💻

Example

This example shows how to create a stash, then display its contents with a summary and a full diff.

bash
# Make some changes in your repo
# Stage or not, then stash them
$ git stash push -m "My changes"
Saved working directory and index state WIP on main: abc1234 My changes

# Show summary of latest stash
$ git stash show
 src/app.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

# Show full diff of latest stash
$ git stash show -p
diff --git a/src/app.js b/src/app.js
index e69de29..d95f3ad 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1 +1,2 @@
-console.log('Hello');
+console.log('Hello World');
Output
Saved working directory and index state WIP on main: abc1234 My changes src/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index e69de29..d95f3ad 100644 --- a/src/app.js +++ b/src/app.js @@ -1 +1,2 @@ -console.log('Hello'); +console.log('Hello World');
⚠️

Common Pitfalls

Some common mistakes when showing stash contents include:

  • Not specifying -p to see detailed changes, so only a summary appears.
  • Assuming git stash show shows all stashes; it only shows the latest by default.
  • Using incorrect stash references like stash@{5} when fewer stashes exist.

Always check your stash list with git stash list before showing contents.

bash
Wrong:
$ git stash show stash@{5}
# Error if stash@{5} does not exist

Right:
$ git stash list
stash@{0}: WIP on main: abc1234 My changes
stash@{1}: WIP on main: def5678 Another change

$ git stash show stash@{1} -p
📊

Quick Reference

CommandDescription
git stash showShow summary of latest stash changes
git stash show -pShow full diff of latest stash
git stash show stash@{n}Show summary of stash number n
git stash show stash@{n} -pShow full diff of stash number n
git stash listList all stashes with their references

Key Takeaways

Use git stash show -p to see detailed changes in a stash.
By default, git stash show shows only the latest stash summary.
Specify stash references like stash@{0} to view specific stash contents.
Check your stash list first with git stash list to avoid referencing non-existent stashes.
The stash diff output helps you understand what changes are saved before applying or dropping a stash.