894

I want to inspect a stash and find out what changes it would make if I applied it to working tree in its current state.

I know I can do a git diff on the stash, but this shows me all the differences between the working tree and the stash, whereas I'm just interested to know what the stash apply is going to change.

2
  • 8
    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). Commented Aug 11, 2017 at 13:46
  • 1
    Note if you use Visual Studio, you can actually just double-click the stash entry from the Git Changes window to preview the changes that stash pop would make
    – bobobobo
    Commented Nov 3, 2021 at 15:00

18 Answers 18

1159

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}
11
  • 46
    Use git stash show -p stash@{0} to see a specific stash. 0 shows the last tone, 1 the second last one.. etc. git stash list will show all the available.
    – brita_
    Commented Jul 18, 2014 at 21:13
  • 18
    If you are using PowerShell, you will have to put the stash name in quotes. (ie: git stash show -p 'stash@{0}') Commented Jul 30, 2014 at 18:57
  • 1
  • 2
    If you want to save diff in file use git stash show -p stash@{0}> stash.txt
    – S_K
    Commented Feb 14, 2019 at 9:19
  • 3
    In 2019 you can just type git stash show [-p] [stash index number] Commented Nov 25, 2019 at 12:13
131

To view a current list of stash:

git stash list

You'll see a list like this:

stash@{0}: WIP on ...
stash@{1}: ...
stash@{2}: ...
...

To view diff on any of those stashes:

git stash show -p stash@{n}
55

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.

gitk viewing a stash

10
  • 6
    You can provide multiple stash@{X} values on the command-line to see more results at once, but I haven't found a simple way to just say 'show all stash entries' in gitk. Commented Jun 3, 2014 at 17:59
  • 7
    gitk stash seems be shorthand for gitk stash@{0} Commented Jun 4, 2014 at 17:49
  • 4
    to show all stashes in gitk you can use gitk `git stash list --pretty=format:%gd` and then search for "WIP on" to jump to next stash. Commented Jun 8, 2016 at 10:31
  • 2
    gitk --reflog lets you see all the stashes, and more. Commented Jun 22, 2016 at 19:30
  • 2
    @IkarPohorský I've posted a new answer which includes instructions for cmd AND which shows just the stashes, not the other commits: stackoverflow.com/a/57395752/983949
    – JBert
    Commented Aug 7, 2019 at 13:36
32

To view all the changes in an un-popped stash:

git stash show -p stash@{0}

To view the changes of one particular file in an un-popped stash:

git diff HEAD stash@{0} -- path/to/filename.php
2
  • in case one does not remember the filenames it also works for all files changed git diff HEAD stash@{0}
    – Simeon
    Commented Apr 18, 2017 at 9:27
  • Just for clarity: -p is short for --patch. The option comes from git-diff. If you prefer the long form you can write git stash show --patch.
    – Peterino
    Commented May 28, 2019 at 6:08
9

When this question was first asked, this may not have been an option, but, if you use PyCharm, you can use the UnStash Changes tool (VCS->Git->UnStash Changes...). This allows you to view the list of stashed changes, as well as pop, drop, clear, or apply (into a new branch if desired):

Unstash Changes Window

and view the changed files per stash:

Paths Affected Window

as well as diffs per file. In the diffs you can cherry-pick individual changes to apply from the stashed changes to the working branch (using the left-pointing chevron):

enter image description here

1
  • thank you! I use PhpStorm or Intellij, I didn't know about this feature. Commented Mar 16, 2022 at 19:05
9

The following command can be used to extract diff of stashed change against 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.

  1. git stash show

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.

  1. git show

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.

  1. git diff

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} -- <filename>
  1. git difftool

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} <commit-hash>

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

9
git stash show -p <index number of stash stack>

To find index number:

git stash list

Example: git stash show -p 1

7

yes the best way to see what is modified is to save in file like that:

git stash show -p stash@{0} > stash.txt
6

Beyond the gitk recommendation in Is it possible to preview stash contents in git? you can install tig and call tig stash. This free/open console program also allows you to choose which stash to compare

2
6

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 See what's in a stash without applying it)

5

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 to stash@{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.

4

View list of stashed changes

git stash list

For viewing list of files changed in a particular stash

git stash show -p stash@{0} --name-only

For viewing a particular file in stash

git show stash@{0} path/to/file
4

I like how gitk can show you exactly what was untracked or sitting in the index, but by default it will show those stash "commits" in the middle of all your other commits on the current branch.

The trick is to run gitk as follows:

gitk "stash@{0}^!"

(The quoting is there to make it work in Powershell but this way it should still work in other shells as well.)

If you look up this syntax in the gitrevisions help page you'll find the following:

The r1^! notation includes commit r1 but excludes all of its parents. By itself, this notation denotes the single commit r1.

This will apparently put gitk in such a mode that only the immediate parents of the selected commit are shown, which is exactly what I like.


If you want to take this further and list all stashes then you can run this:

gitk `git stash list '--pretty=format:%gd^!'`

(Those single quotes inside the backticks are necessary to appease Bash, otherwise it complains about the exclamation mark)

If you are on Windows and using cmd or Powershell:

gitk "--argscmd=git stash list --pretty=format:%gd^!"
3

You can view all stashes' list by the following command:

$ git stash list

stash@{0}: WIP on dev: ddd4d75 spelling fix

stash@{1}: WIP on dev: 40e65a8 setting width for messages

......

......

......


stash@{12}: WIP on dev: 264fdab added token based auth

Newest stash is the first one.

You can simply select index n of stash provided in the above list and use the following command to view stashed details

git stash show -p stash@{3}

Similarly,

git stash show -p stash@{n}

You can also check diff by using the command :

git diff HEAD stash@{n} -- /path/to/file
3

You can review the stashed changes in VSCode with gitlen extension

screenshot of gitlen stashes

1
  • 2
    Useful to know. Though, they were specifically asking about in git, not within a specific product. Commented Jul 14, 2020 at 6:20
3

Several answers have mentioned the -p (or --patch) flag on git stash show

However, it might also be worth mentioning that you can make this the default behaviour when showing a Git stash (ie. git stash show stash@{0}), either by using git config:

git config --global stash.showPatch true

...or in your .gitconfig file:

[stash]
  showPatch = true

This makes git stash show behave like git show by default. If and when you do just want to see the diffstat (ie. summary of lines added / deleted), you can still see that via the --stat flag (again, like with git show):

git stash show --stat stash@{0}
2

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.
1

Show all stashes

File names only:

for i in $(git stash list --format="%gd") ; do echo "======$i======"; git stash show $i; done

Full file contents in all stashes:

for i in $(git stash list --format="%gd") ; do echo "======$i======"; git stash show -p $i; done

You will get colorized diff output that you can page with space (forward) and b (backwards), and q to close the pager for the current stash. If you would rather have it in a file then append > stashes.diff to the command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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