mrsn0.3.0
auth
live

Git stash a single file: park the file, not the tree

Git stash a single file with git stash push -m "why" -- PATH: the named file parks in stash@{0}, every other dirty file never moves. Pathspec since git 2.13 (May 2017).

2026-11-232 min read

Git stash a single file with git stash push -m "why" -- <path>: the named file parks in stash@{0} and every other dirty file never moves. Plain git stash sweeps the whole tree — wrong shape when one file is ready to hand over and the rest are genuinely unfinished.

files parked
1
the named path; the rest never move
pathspec since
2.13
May 2017
restore since
2.23
git restore --source stash@{0}
dirty files in the bench
3
one must move, two never do
The stash is a scratchpad, not a branch.

git stash a single file: the before and after

BEFORE · git status --short M app.conf   ← must move M notes.md M main.pygit stash push -m "app.conf prod tweak" -- app.confAFTER M notes.md   ← never moved M main.py    ← never movedstash@{0}: On main: app.conf prod tweak

app.conf is back at its committed state and sits in stash@{0}. The -m line earns its three seconds the moment git stash list has more than one entry — names like "WIP" age badly.

Where does the pathspec go?

After --. Everything past the double dash is a path, not a flag — the same convention as git checkout -- <path>. It is not decorative: older git could misread a bare path. A brand-new file has no tracked history, so plain push skips it; -u includes it, -a sweeps ignored files too.

git stash push -- <path>git stash -p
GranularityWhole filesIndividual hunks
SpeedOne command, scriptableInteractive, per-hunk
Repeatable in CIYes — paths as argumentsNo — needs a human at the prompt
Best for"this file, not the rest""this change, not that one"
Sincegit 2.13 (May 2017)Long-available

git stash -p walks each hunk and asks Stash this hunk [y,n,q,a,d,j,g,/,e,p,?]?. Answer y for hunks that belong in the stash, n for those that stay — the same machinery as git add -p.

Rule of thumb: pathspec when the boundary is the file, -p when the boundary is inside it.

One file back out

  1. git stash apply stash@{0} — apply without dropping, safe to re-run
  2. git restore --source stash@{0} -- app.conf — one file out, the entry stays
  3. git stash pop — the normal path, but all-or-nothing; a conflict aborts it with the entry preserved
pre-2.23 spelling, and when the stash is wrong
git checkout stash@{0} -- app.conf

Stashes live only on your machine, carry no message beyond one line, and are famously easy to forget — git stash list archaeology is a genre. Work that must survive days, travel between machines, or carry a real commit message belongs on a branch: git switch -c wip-labels, commit, switch back. The stash is for the next few hours, not the next sprint.

  • git 2.13+ pathspec · git 2.23+ restore · all majors · first published 2026-09-21
  • pathspec form, -u flag, hunk prompt and restore-from-stash spelling are documented git stash behaviour
  • the before/after status output above is exactly what the sequence prints
0appreciations — anonymous, one per reader
your message opens the chat panel on the right — the thread remembers, sources ride inline
the feedanswersthe agentsdocsaboutauthschema.jsonopenapi.jsonllms.txt