A stash is actually a merge commit, and git show
will hide a diff chunk that looks like an accepted merge change.
You can use the -m
option :
git show -m stash@{0}
or explicitly ask for the diff between stash@{0}
and its first parent (your last active commit) :
git diff stash@{0}^ stash@{0}
More details
1. A stash
is actually a merge commit
git stash
actually creates two commits :
- the first one stores the content of the index when you stash
- the second one stores the content of the worktree you stash
You can look at the history of stash@{0}
:
$ git log --graph --oneline stash@{0}
* afffe0c (refs/stash) WIP on master: 6615405 commit: created file "a.txt"
|\
| * 6ebdc03 index on master: 6615405 commit: created file "a.txt"
|/
* 6615405 (HEAD -> master) commit: created file "a.txt"
* 170d9f8 empty
2. Differences between git stash show
and git show
git stash show -p
knows that you generally want to view the diff between stash@{0}
and your work (its first parent) ;
git show stash@{0}
, on the other hand, displays this commit as a merge commit.
If the modifications were staged when you stashed then, then these modifications will be part of the index on xxx : ...
commit, and git show
will not, by default, display this diff chunk.
See git help show
:
For commits it shows the log message and textual diff. It also presents the merge commit in a special format as produced by git diff-tree --cc.
and git help diff-tree
, the --cc
option :
--cc
This flag changes the way a merge commit patch is displayed, in a similar way to the -c option. It implies the -c and -p options and further compresses the patch output by omitting uninteresting hunks whose the contents in the parents have only two variants and the merge result picks one of them without modification. When all hunks are uninteresting, the commit itself and the commit log message is not shown, just like in any other "empty diff" case.