View the Content of the Most Recent Stash
To view the contents of the most recent git stash, we can simply use the following command:
git stash show -p
The -p
flag is short for the --patch
flag. Using either one is the same.
View the Contents of a Specific Stash
To see changes in a specific stash, you can simply specify the stash index in the following way:
git stash show -p stash@{2}
Alternatively, stashes may also be referenced just by specifying the stash index like so:
git stash show -p 2
How to Find a Stash Index?
To find a stash index, you can simply use the following command to list out all the stashes:
git stash list
The result of this looks something like the following:
stash@{0}: WIP on master: 458853e Fixing something stash@{1}: WIP on dev: 8d68533 Updated comment stash@{2}: WIP on dev: 7922161 Refactoring ...
Please note that if you apply or remove a stash, all other stashes in the list are re-indexed.
Saving the Stash Contents to a Text File
For convenience, the contents of the stash can be output to a text file like so:
git stash show -p stash@{2} > stash.txt
Or, alternatively, you can use the shorter syntax by just using the stash index:
git stash show -p 2 > stash.txt
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.