2717

How do I see what is inside a stash without actually applying it?

10
  • 8
    He's not calling stash an application, he's referring to the act of applying the stash. Unclear terminology aside, the question is the same.
    – ellotheth
    May 23, 2012 at 20:47
  • 5
    To get colorized diff output: git stash show -p stash@{1} >~/.diff && vim ~/.diff (doesn't have to be vim. any text editor as long as your text editor has syntax highlighting support for diff output). Aug 11, 2017 at 13:46
  • 10
    @TrevorBoydSmith or just git stash show -p stash@{1} | view - Nov 14, 2017 at 18:19
  • a little weird observation, on centos-7 view is aliased to vi and man view displays the man page for vim. (i'll have to change my .bashrc to use your new trick (it's better than my old way IMO).) Dec 1, 2017 at 20:56
  • 1
    git stash show <Stash Number>
    – vidur punj
    Feb 28, 2022 at 8:21

1 Answer 1

3754

From man git-stash (which can also be obtained via git help stash):

The modifications stashed away by this command can be listed with git stash list, inspected with git stash show, and ...

show [<stash>]
    Show the changes recorded in the stash as a diff between the stashed
    state and its original parent. When no <stash> is given, shows the
    latest one. By default, the command shows the diffstat, but it will
    accept any format known to git diff (e.g., git stash show -p stash@{1}
    to view the second most recent stash in patch form).

Note: the -p option generates a patch, as per git-diff documentation.

List the stashes:

git stash list

Show the files in the most recent stash:

git stash show

Show the changes of the most recent stash:

git stash show -p

Show the changes of the named stash:

git stash show -p stash@{1}

Or in short:

git stash show -p 1 

If you want to view changes of only the last stash:

git stash show -p 0
32
  • 14
    One very useful feature one may consider is to list contents of all local stashes: git stash list | awk -F: ‘{ print “\n\n\n\n”; print $0; print “\n\n”; system(“git –no-pager stash show -p ” $1); }’ | less It helped me a lot in the past (cleaning stashes stack). Aug 28, 2013 at 7:40
  • 52
    Same command with fixed quotes and without piping to less so you can still see the diff highlighting: git stash list | awk -F: '{ print "\n\n\n\n"; print $0; print "\n\n"; system("git stash show -p " $1); }' Press [Q] to exit each stash.
    – Gerry
    Sep 22, 2013 at 14:38
  • 25
    git stash show -p stash@{1} lists all the files in a stash. Is it possible to view jus one specific file from the stash? Feb 2, 2014 at 14:02
  • 124
    git stash show -p stash@{0} --name-only shows just the names of the files (not the contents) in your first stash.
    – bergie3000
    Jun 10, 2015 at 17:57
  • 36
    @mrgloom If you want to see the stashed changes for a single file, then something like git diff stash@{0}^! -- file.txt will do it. See here for more details.
    – simont
    Apr 24, 2019 at 22:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.