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
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
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:
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.
- List the current stashes:
- View the summary of the stash's changes:
example.txt was modified, with 4 lines affected.
- View the detailed diff of the stash:
This shows exactly what the stash changed in example.txt.
Command reference
| Action | Command | Description |
| List all stashes | git stash list | List all stashes with identifier and descriptions. |
| Show stash summary | git stash show stash@{index} | Summarize changes in terms of affected files. |
| Show stash detailed changes | git stash show -p stash@{index} | Display detailed changes like a diff for inspection. |
Related reading
- Selectively revert or checkout changes to a file in Git?
- Set up git to pull and push all branches
- Set Visual Studio Code to be global Git editor on OSX
- setting tabwidth to 4 in git show / git diff
- Setting up and using Meld as your Git difftool and mergetool
- Should a repository interface expose a clear() method to clear the cache of the implementation?
- Should composer.lock be committed to version control?
- Should Gemfile.lock be included in .gitignore?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.