In git stash manpage you can read that (in "Discussion" section, just after "Options" description):
A stash is represented as a commit whose tree records the state of the working directory, and its first parent is the commit at HEAD when the stash was created.
So you can treat stash (e.g.
stash@{0}
is first / topmost stash) as a merge commit, and use:$ git diff stash@{0}^1 stash@{0} -- <filename>Explanation:
stash@{0}^1
shortcut means first parent of given stash, which as stated in explanation above is commit at which changes were stashed away. We use this form of "git diff" (with two commits) becausestash@{0}
/refs/stash
is a merge commit, and we have to tell git which parent we diff againts. More cryptic:$ git diff stash@{0}^! -- <filename>should also work (see git rev-parse manpage for explanation of
rev^!
syntax, in "Specifying ranges" section).Likewise, you can use git checkout to check a single file out of the stash:
$ git checkout stash@{0} -- <filename>or to save it under another filename:
$ git show stash@{0}:<full filename> > <newfile>(note that here <full filename> is full pathname of a file relative to top directory of a project (think: relative to
stash@{0}
)).
Progittip