git stash
software development
version control
programming tips
git commands

How to see what's in a git stash without applying it

Codemia Knowledge Hub ·

Run git stash show -p stash@{index} to see the full diff of a stash without applying it. Plain git stash show stash@{index} gives only a summary of which files changed, and git stash list tells you which index to use.

A stash shelves the changes in your working directory and index so you can switch branches or do other work without committing unfinished code. Checking a stash before you bring it back is worthwhile because git stash apply writes the stashed changes into your working directory, which can cause merge conflicts or surprises if you are not sure what the stash contains.

Listing all stashes

bash
git stash list

Each entry has an identifier of the form stash@{index} and the message recorded when the stash was made.

Showing which files a stash changed

bash
git stash show stash@{index}

This prints a diffstat, like git diff --stat: the files that were altered and how many lines changed, but not the changes themselves.

Showing the full diff of a stash

Add the -p (patch) flag:

bash
git stash show -p stash@{index}

The output is a regular diff, like git diff, with line-by-line changes, additions and deletions for every file in the stash. Nothing in your working directory is touched, so you can examine the stash thoroughly before deciding to apply it, keep it, or drop it.

Example: inspecting a stashed change to example.txt

Say example.txt was modified and stashed, and you have not decided whether to bring the change back.

  1. List the current stashes:
bash
   $ git stash list
   stash@{0}: WIP on main: a1b2c3 example changes
  1. View the summary of the stash's changes:
bash
   $ git stash show stash@{0}
   example.txt | 4 +++-

example.txt was modified, with 4 lines affected.

  1. View the detailed diff of the stash:
bash
1   $ git stash show -p stash@{0}
2   diff --git a/example.txt b/example.txt
3   index 83db48f..1d0d27b 100644
4   --- a/example.txt
5   +++ b/example.txt
6   @@ -1,3 +1,5 @@
7    Lorem ipsum dolor sit amet,
8   -consectetur adipiscing elit.
9   +consectetur adipiscing elit,
10   +sed do eiusmod tempor incididunt
11   +ut labore et dolore magna aliqua.
12    Ut enim ad minim veniam,

This shows exactly what the stash changed in example.txt.

Command reference

ActionCommandDescription
List all stashesgit stash listList all stashes with identifier and descriptions.
Show stash summarygit stash show stash@{index}Summarize changes in terms of affected files.
Show stash detailed changesgit stash show -p stash@{index}Display detailed changes like a diff for inspection.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 11,000 interview practice questions for 300+ companies, searchable by company and role.

Browse interview questions