I see here you can apply/unapply a stash and even create a new branch off of a stash. Is it possible to simply see what is inside the stash without actually applying it?
Asked
Active
Viewed 8.5e+01k times
2084
-
7He'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
-
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:46
-
4@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
1 Answers
2889
From the man git-stash
page:
The modifications stashed away by this command can be listed with git stash list, inspected with git stash show
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).
To list the stashed modifications
git stash list
To show files changed in the last stash
git stash show
So, to view the content of the most recent stash, run
git stash show -p
To view the content of an arbitrary stash, run something like
git stash show -p stash@{1}
Ashutosh Chamoli
- 847
- 10
- 25
simont
- 57,012
- 16
- 110
- 130
-
That is exactly what I wanted - thanks! Wonder why it's not on the git-scm page? – Chris Abrams May 23 '12 at 20:24
-
9One 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
-
38Same 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
-
19`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
-
3For 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
-
3Same 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
-
4`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
-
98`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
-
3Note 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
-
5`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
-
14@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
-
3
-
Related 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
-