I often put work away for later, then other stuff comes along, and a few weeks later, I want to inspect the stash, and find out what changes it would make if I applied it to
The following command can be used to extract diff of stashed change againest any other stash or commit or branch or HEAD.
git stash show
git show
git diff
git difftool
Let’s see, how we can use each of the above mentioned commands.
The simple command git stash show gives very brief summary of changes of file, but will not show the diff of changes against current HEAD.
The command git-show is used to see various types of objects.
The command git-show is not only used to visualize stash changes, but also used to see one or more objects like blobs, trees, tags and commits.
The command git-diff is also one of common command which is used to show changes between commits, commit and working tree, etc.
By default, git diff will show the diff of selected stash against(modified files) current state of repository unless other stash reference or commit is specified.
To get difference between top most stash stash@{0} and master branch:
$ git diff stash@{0} master
Only display the names of file not diff of changes:
$ git diff --name-only stash@{0} master
See the diff between selected stashes for a selected file:
$ git diff stash@{0}^1 stash@{0} --
The command git-difftool can also be used to find diff between selected stash and selected commit or branch or stash
See the difference between latest two stashes:
$ git difftool stash@{0} stash@{0}^1
git difftool --dir-diff stash@{0} stash@{0}^1
Summary:
Commands which are useful to extract the diff from selected stash git stash show, git show, git diff, git difftool .
See difference using command git stash show,
git stash show -p stash@{0}
See the changes in the stash using command git show,
git show stash@{1}
See the difference between latest stash and selected commit using command git diff,
git diff stash@{0}
References:
https://howto.lintel.in/how-to-see-stashed-changes-using-git-stash/
https://git-scm.com/docs/git-show
https://git-scm.com/docs/git-stash
In additional to the existing answers which suggests using (to show the diff of the third-to-last stash)
git stash show -p stash@{2}
Note that in the git-stash documentation, it is written that
Stashes may also be referenced by specifying just the stash index (e.g. the integer
n
is equivalent tostash@{n}
).
Therefore it's also possible to use (this is equivalent to the command above)
git stash show -p 2
Which should also avoid some Powershell issues.
git stash show
will show you the files that changed in your most recent stash. You can add the -p
option to show the diff.
git stash show -p
If the stash you are interested in is not the most recent one, then add the name of the stash to the end of the command:
git stash show -p stash@{2}
I use this to see all my stashes with colour diff highlighting (on Fedora 21):
git stash list |
awk -F: '{ print "\n\n\n\n"; print $0; print "\n\n";
system("git -c color.ui=always stash show -p " $1); }' |
less -R
(Adapted from Git: see what's in a stash without applying stash)
I'm a fan of gitk
's graphical UI to visualize git repos. You can view the last item stashed with:
gitk stash
You can also use view any of your stashed changes (as listed by git stash list
). For example:
gitk stash@{2}
In the below screenshot, you can see the stash as a commit in the upper-left, when and where it came from in commit history, the list of files modified on the bottom right, and the line-by-line diff in the lower-left. All while the stash is still tucked away.
First we can make use of git stash list to get all stash items:
$git stash list
stash@{0}: WIP on ...
stash@{1}: WIP on ....
stash@{2}: WIP on ...
Then we can make use of git stash show stash@{N}
to check the files under a specific stash N
. If we fire it then we may get:
$ git stash show stash@{2}
fatal: ambiguous argument 'stash@2': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
The reason for this may be that the shell is eating up curly braces and git sees stash@2
and not stash@{2}
. And to fix this we need to make use of single quotes for braces as:
git stash show stash@'{2'}
com/java/myproject/my-xml-impl.xml | 16 ++++++++--------
com/java/myproject/MyJavaClass.java | 16 ++++++++--------
etc.