9

Using the command line tool git-stash, how can I view both the stash message, as well as the diff, for a given stash?

The documentation for git stash mentions that you can configure how a diff is shown, but it doesn't mention messages anywhere other than in how to create a stash.

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

2 Answers2

11

A stash is stored as a normal commit, hence you can use usual Git commands to display it, like:

git show stash@{1}

to show message and diff for stash@{1}. Since stashes are stored as commits with two parents (one for the index, and the other for the HEAD at the time the stash was created), the command above will show a combined diff.

Obviously, as others already pointed out, git stash list -p or git list with stash.showPatch=true (new in 2.7.0) also show diff + message, for all stashes.

Daniel Liuzzi
  • 16,807
  • 8
  • 52
  • 57
Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65
  • I get `++` and `--` in the diff rather than `+` and `-`. Is that normal? – Andrew Grimm Feb 19 '16 at 23:50
  • 1
    Stash commits are stored with two parents, the git diff show runs is reporting the comparison between the stashed worktree state and the stashed index state as well as the commit that was checked out at the time. – jthill Feb 22 '16 at 17:27
  • Note that `stash.showPatch=true` only works for `git stash show`; it has no effect on `git stash list` so you still need `-p` there ([see](https://git-scm.com/docs/git-stash/2.37.2#Documentation/git-stash.txt-show-u--include-untracked--only-untrackedltdiff-optionsgtltstashgt)) – Daniel Liuzzi Aug 21 '22 at 15:14
9

Are you looking for a command like

git stash list -p

This shows the diff of each stash, together with the messages you provided.

Edit: In case you know which stash number you want to show (i.e., not show the entire list but one specific stash), you can do

git stash list -p -n 1 --skip i

where i is the number of the stash you want to show. (this will show stash@{i}).

As mentioned in the manual, the git stash list command takes options for formatting similar to git log, see the git log man page

The -p option ensures that all the information you want is printed (you can play around with the formatting as explained on the git log man page)

The option -n 1 ensures that only one stash is printed, also see the git log man page

The option --skip i tells git to not print the first i stashes, hence, combined with the option n 1, only stash@{i} will be shown. Again, see the git log man page

BartBog
  • 1,889
  • 14
  • 28