Inspect the changes saved in a Git stash

Inspect tracked and untracked stash contents, compare saved snapshots, and restore changes for review without accidentally dropping the stash.

Best practices
Illustration of Git history and collaboration

Use git stash show -p to inspect the latest stash as a patch. To inspect an older entry, find its selector with git stash list and quote that selector in the command.

git stash list
git stash show -p 'stash@{1}'
git stash show --stat 'stash@{1}'

Here, stash@{1} means the second entry in the current list. Selectors change when you add or remove entries. Without a selector, these commands use the latest stash; without a format option, display settings such as stash.showPatch and stash.showStat can change the output.

Include saved untracked files

A stash created with git stash push -u can contain untracked files. Saving them and displaying them are separate choices:

# Include saved untracked files in the patch
git stash show -p --include-untracked 'stash@{0}'

# Show only those untracked files
git stash show -p --only-untracked 'stash@{0}'

The display option cannot recover a file that was never saved. Ordinary stash push does not save untracked files; -u adds them, while -a also includes ignored files. See the stash command reference.

Compare the saved state with another revision

stash show compares the saved tracked files with the commit on which the stash was created. It does not compare them with your current working directory.

# Changes from main to the stash's tracked-file snapshot
git diff main 'stash@{0}'

# Changes from the saved tracked snapshot to the current working tree
git diff 'stash@{0}'

The argument order controls the direction of the diff. These tree comparisons do not include a stash's separately stored untracked files. Use stash show --include-untracked when reviewing the whole saved change. See git-diff.

For an editable review, first commit or stash unrelated current work. If you create another stash, run git stash list again and replace stash@{0} below with the entry you intend to inspect. Start from that stash's original base and apply it without dropping the entry:

git switch -c inspect-stash 'stash@{0}^1'
git stash apply --index 'stash@{0}'
git diff main
git status --short

Use a new branch name. --index attempts to restore the staged state too. Review untracked files separately, and commit the changes you intend to preserve. Creating the branch alone does not commit the restored work.

The shorter git stash branch inspect-stash 'stash@{0}' also restores the original state, but it drops that stash entry when the operation succeeds. Account for that side effect before using it as an inspection command.

Apply or remove an entry deliberately

git stash apply 'stash@{1}'  # Restore changes and retain the entry
git stash pop               # Restore the latest entry; drop it on success

Both can encounter conflicts. After checking and preserving the result, use git stash list again before selecting an entry to remove with git stash drop. A changed list may have different numbers.

FAQ

Do stash selectors need quotes?

Use single quotes in Bash, zsh, and PowerShell examples. Quoting keeps braces and other revision syntax from being interpreted by the shell.

How long can I keep a stash?

Do not treat a stash as durable backup. Its availability depends on references, reflog maintenance, and object pruning. For work you need to keep, restore it on a branch, commit the intended files, and back up that branch. A successful restore is not itself a commit.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting