How do I see what is inside a stash without actually applying it?
Asked
Active
Viewed 1.3M times
2607
-
8He's not calling `stash` an application, he's referring to the act of applying the stash. Unclear terminology aside, the question is the same. – ellotheth May 23 '12 at 20:47
-
2To 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). – Trevor Boyd Smith Aug 11 '17 at 13:46
-
10@TrevorBoydSmith or just `git stash show -p stash@{1} | view -` – Aryeh Leib Taurog Nov 14 '17 at 18:19
-
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).) – Trevor Boyd Smith Dec 01 '17 at 20:56
-
@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` – Keith Thompson Dec 17 '19 at 22:59
-
These two commands are awesome git diff stash@{1}^! you will get the stash id from the git stash list command git stash list – Amitesh Bharti Jan 28 '21 at 12:19
-
1git stash show
– vidur punj Feb 28 '22 at 08:21 -
Clearly this question and answer should be open and the other closed, just given the relative view counts and the succinct, comprehensive exchange. Food for SO thought. – Kay V Mar 09 '22 at 04:01
-
`This question already has answers here:` yeah whataver this one has better google rank and more upvotes but that one have better answer than overcomplicated manbook one like in this questiones – buncis Mar 13 '23 at 14:23
-
git stash show -p – buncis Mar 13 '23 at 14:24
1 Answers
3621
From man git-stash
(which can also be obtained via git help stash
):
The modifications stashed away by this command can be listed with
git stash list
, inspected withgit stash show
, and ...
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 form).
Note: the -p
option generates a patch, as per git-diff
documentation.
List the stashes:
git stash list
Show the files in the most recent stash:
git stash show
Show the changes of the most recent stash:
git stash show -p
Show the changes of the named stash:
git stash show -p stash@{1}
Or in short:
git stash show -p 1
-
13One very useful feature one may consider is to list contents of all local stashes: `git stash list | awk -F: ‘{ print “\n\n\n\n”; print $0; print “\n\n”; system(“git –no-pager stash show -p ” $1); }’ | less` It helped me a lot in the past (cleaning stashes stack). – Dariusz Cieslak Aug 28 '13 at 07:40
-
50Same command with fixed quotes and without piping to less so you can still see the diff highlighting: `git stash list | awk -F: '{ print "\n\n\n\n"; print $0; print "\n\n"; system("git stash show -p " $1); }'` Press [Q] to exit each stash. – Gerry Sep 22 '13 at 14:38
-
23`git stash show -p stash@{1}` lists all the files in a stash. Is it possible to view jus one specific file from the stash? – Varun Natraaj Feb 02 '14 at 14:02
-
4For anyone skimming the "git stash show -p stash@{1} was what I was looking for" answer like me, {1} is the *2nd* stash, not the first. Numbering starts at 0. – Greg May 12 '14 at 15:06
-
4I believe a simple `git show stash{0}` will get you the same result. – Thalis K. Jul 17 '14 at 09:06
-
4Same command with diff highlighting in a single less invocation: `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` – seanf Apr 30 '15 at 02:41
-
5`git stash show -p -1`. This is equivalent to: `git stash show -p stash@{0}`, but shorter. – Doron Gold May 20 '15 at 14:09
-
117`git stash show -p stash@{0} --name-only` shows just the names of the files (not the contents) in your first stash. – bergie3000 Jun 10 '15 at 17:57
-
1
-
@ThalisK. I think you may have meant `git stash show stash@{0}` Your version lacked the `stash` subcommand (there is no such thing as `git show`) and also the `@` sign. – iconoclast Feb 27 '16 at 02:13
-
@iconoclast, `git show stash@{0}` works as well (equivalent to `git stash show -p stash@{0}`). `stash@{0}` is a valid revision name. – Franklin Yu Apr 26 '16 at 05:54
-
Ah, interesting to know about that shorter way of accomplishing the same thing. I tested Thalis's original version, but it didn't work because the `@` was missing. – iconoclast Apr 27 '16 at 20:28
-
3If you're using [fish](http://fishshell.com), you need to escape the braces: `git stash show -p stash@\{0\}` – George WS Jun 20 '16 at 04:20
-
4Note that this doesn't show added files! See: [In git, is there a way to show untracked stashed files without applying the stash?](http://stackoverflow.com/questions/12681529/in-git-is-there-a-way-to-show-untracked-stashed-files-without-applying-the-stas) – antak Feb 08 '17 at 01:37
-
7`git stash show -p > ~/Desktop/stash.txt` outputs the diff to a file :P – LittleLittleQ May 05 '17 at 03:51
-
@Gerry here's another way 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). – Trevor Boyd Smith Aug 11 '17 at 13:45
-
2`git stash show stash@{0}` shows the files that are modified. Add the `-p` flag to display the actual changes inside the files. – wranvaud Sep 21 '17 at 13:12
-
Interestingly, `git help stash` makes no mention of any available options for `git stash show`. – haridsv Jan 07 '19 at 08:31
-
how to copy the change from stash ? .. i mean if i copy some lines from terminal it pastes with the punchuations like + which appears in beginning of each new line. – Ammar Mujeeb Apr 10 '19 at 10:52
-
1
-
32@mrgloom If you want to see the stashed changes for a single file, then something like `git diff stash@{0}^! -- file.txt` will do it. See [here](https://stackoverflow.com/questions/1105253/how-would-i-extract-a-single-file-or-changes-to-a-file-from-a-git-stash) for more details. – simont Apr 24 '19 at 22:57
-
6
-
1Related if you got too many revision specified: https://stackoverflow.com/questions/18884567/too-many-revisions-git-message – Shinjo Aug 21 '19 at 05:19
-
1
-
1You can also use `stash@{n}` format in other places, e.g., `git show` to see the full stashed file (instead of diff), e.g., `git show stash@{0}:path/to/file` – haridsv Feb 19 '21 at 08:39
-
1
-
-
-
-
-
2@TobiasFeil It seems to me that any number in the stash list can be used to visualize a specific stash, e.g. `git stash show -p 2` – Antonio Jul 01 '22 at 09:11
-
Not sure what triggers behind, but `git stash show --oneline` also shows the delta of a stash (without untracked files) on terminal. – Harshit Gupta Mar 26 '23 at 09:07