git – See what’s in a stash without applying it

The Question :

1966 people think this question is useful

I see here you can apply/unapply a stash and even create a new branch off of a stash. Is it possible to simply see what is inside the stash without actually applying it?

The Question Comments :
  • 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.
  • 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).
  • @TrevorBoydSmith or just git stash show -p stash@{1} | view -
  • 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).)
  • @AryehLeibTaurog: Assuming view is, as usual, equivalent to vi or vim in read-only mode, it can’t read a file from standard input (it reads commands from stdin). git stash show -p stash@{1} | less

The Answer 1

2728 people think this answer is useful

From the man git-stash page:

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

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

To list the stashed modifications

git stash list

To show files changed in the last stash

git stash show

So, to view the content of the most recent stash, run

git stash show -p

To view the content of an arbitrary stash, run something like

git stash show -p stash@{1}

Add a Comment