Git Stash Inspection, Application, and Recovery
Inspect, restore, remove, and branch-recover temporary Git stash state without confusing stash management with durable branch history.
Intermediate
Learner goal
By the end of this lesson, you should be able to list stash entries, identify a stash by its revision syntax, inspect its changes, apply or pop a stash deliberately, restore the index with --index when appropriate, drop individual entries, clear the stash list, and use stash branch when a clean branch context is the safer recovery path.
A stash entry is addressable Git state
The latest stash is referenced by refs/stash. Older entries are available through that reference's reflog, and Git documents names such as stash@{0}, stash@{1}, and stash@{2.hours.ago}. A numeric stash index such as 0 is also accepted as the corresponding stash entry. This gives stash commands a stable revision-style way to select an entry without turning the stash into a branch.
git stash list
git stash show stash@{0}
git stash show stash@{1}Quick check
Which name selects the most recently created stash entry?
The repository has several stash entries.stash@{0} selects the newest one.
List stash entries with `git stash list`
Use `git stash list` to see the available stash entries. The output normally includes the stash reference, the branch context recorded for the entry, and its message. The command can also accept log options, but this lesson keeps the first inspection step deliberately simple.
git stash list
git stash list --date=localThe list is especially useful before destructive operations. Identify the exact entry first instead of assuming stash@{0} is still the entry you meant to use: every newly created stash changes the numeric ordering.
Quick check
Why can stash@{0} refer to a different piece of work later?
There are two stash entries and you create a third.The new entry becomes stash@{0}; older entries receive later indices.
Inspect a stash with `git stash show`
`git stash show` inspects the changes recorded by a stash. Without a stash argument, Git uses the most recent stash. Supplying a revision makes the target explicit. The default presentation is a diffstat; options such as `--patch` can show the actual patch.
git stash show
git stash show stash@{1}
git stash show --patch stash@{0}When a stash was created with untracked files, `git stash show` can be extended with `--include-untracked` to show those files as well. `--only-untracked` narrows the display to untracked content recorded in the stash. These are inspection choices; they do not change the stash itself.
git stash show --include-untracked stash@{0}
git stash show --only-untracked stash@{0}Quick check
What does `git stash show --patch stash@{1}` primarily change?
stash@{1} already exists.The command displays the selected stash's patch; it does not mutate it.
Apply a stash without deleting it
`git stash apply` restores the selected stash onto the current working tree while leaving the stash entry available for later use. If no stash is named, Git uses the most recent entry. Because applying changes can conflict with current work, inspect the working tree before applying and be prepared to resolve conflicts.
git stash apply stash@{1}
git status --shortThe default application restores the working-tree changes represented by the stash. If you also need the index state restored, use `--index`. That asks Git to try to reinstate the staged state as well; it does not guarantee that an incompatible current state can be merged without conflict.
git stash apply --index stash@{1}Quick check
What distinguishes `git stash apply` from `git stash pop`?
A stash is ready to restore.Use apply when you want the stash to remain available.
Restore staged state with `--index`
A stash can contain both working-tree changes and the index state captured when it was created. `git stash apply --index` asks Git to restore the index state too. Without `--index`, the changes can be applied without recreating their previous staged/unstaged split.
git stash apply --index stash@{0}
git status --short
git diff --cachedThe option is about restoring the index, not about selecting which files were originally stashed. That selection was controlled when the stash was created, for example with `--staged`, `--keep-index`, `--all`, or a pathspec.
Pop a stash when the entry is no longer needed
`git stash pop` applies a stash and removes that stash entry when the application succeeds. If applying the stash causes conflicts, the stash is not removed automatically; Git leaves it available so you can resolve the conflict and decide what to do next.
git stash pop stash@{0}
git status --shortQuick check
After a conflict during `git stash pop`, what should you expect about the stash entry?
The stash cannot be applied cleanly.The stash remains available while you resolve the conflict.
Drop one stash entry
Use `git stash drop` to remove one stash entry from the stash list. Specify the entry when more than one exists; omitting the argument targets the most recent stash.
git stash list
git stash drop stash@{1}
git stash listDropping is a destructive management operation. Confirm the target before running it, particularly because numeric indices can change whenever newer stash entries are created or removed.
Clear the entire stash list
`git stash clear` removes all stash entries. This is broader than `git stash drop`, which targets one entry. Because the command discards the entire stash list, treat it as a deliberate destructive operation rather than routine cleanup.
git stash list
git stash clear
git stash listRecover with `git stash branch`
`git stash branch <branchname> [<stash>]` creates and checks out a new branch starting from the commit at which the selected stash was originally created, then applies the stash to that new working tree and index. If that succeeds and the stash is addressed as a stash@{...} reference, Git drops that stash entry.
git stash branch recover-feature stash@{0}
git status --short
git branch --show-currentThis workflow is useful when applying a stash to the current branch would create conflicts because the current branch has diverged from the commit on which the stash was created. It changes the recovery context rather than attempting to force the stash onto unrelated current work.
Quick check
What starting point does `git stash branch feature stash@{0}` use for the new branch?
The current branch has moved since the stash was made.The recovery branch starts from the stash's original base commit.
A safe inspection-and-restoration workflow
A disciplined stash workflow separates identification from mutation. First list entries and identify the target. Then inspect it. Choose `apply` when you want to retain the entry, or `pop` when a successful restoration should also remove it. Use `--index` only when restoring the staged state is part of the goal. If the current branch is an unsuitable base, consider `stash branch`. Only drop or clear entries after confirming the work is no longer needed.
git stash list
git stash show --patch stash@{0}
git stash apply --index stash@{0}
# resolve/test as needed
git stash drop stash@{0}Quick Check: choose the operation
Quick check
You want to restore a stash but keep it available. Which operation matches that goal?
A stash should remain available after restoration.Use `git stash apply`.
Practice what you learned
Use the dedicated Git code-completion exercise for this lesson.
Official references
This lesson uses only the live official Git documentation. `git-stash` defines `list`, `show`, `apply`, `pop`, `drop`, `clear`, and `branch`, including `--index`, stash revision naming, conflict behavior, and the original-base behavior of `stash branch`. `gitrevisions` defines Git revision syntax used by stash references. No third-party documentation is used.
Thanks for your feedback.
Mark this learning resource complete to track your learning progress.