Is it possible to tell whether a stash has already been applied, and therefore is no longer required, without doing git stash apply
? Assume that I'm only using one branch.
This could be prevented by using pop
rather than apply
when applying a stash, and therefore get rid of the stash each time it gets applied. However, I sometimes use git stash to keep a snapshot of work in progress, rather than only using it to switch from one task to another. Using pop would defeat that somewhat.
Git Stash List. The Git stash list command will pull up a list of your repository's stashes. Git will display all of your stashes and a corresponding stash index. Now, if you wish to view the contents of a specific stash, you can run the Git stash show command followed by stash@ and the desired index.
You can git diff and inspect the output. If there is none, then there is nothing to stash . If there is output, then you can grep to parse it for specific things you need.
Git stashes are saved until your hard disk dies (unlike commits, which are usually transmitted to some other computer via git push so will outlive a hard disk failure). You can have as many stashes as you want.
Retrieving stashed changes You can reapply stashed changes with the commands git stash apply and git stash pop . Both commands reapply the changes stashed in the latest stash (that is, stash@{0} ). A stash reapplies the changes while pop removes the changes from the stash and reapplies them to the working copy.
You can use the following shell script to get git stash list
prefixed with checkmarks if they have already been applied or there is no need to apply them as there is no difference.
git stash list | while read line; do \
ref=${line%%:*}; \
prefix=$(test $(git diff $ref | wc -l) = "0" && echo "✔ " || echo " "); \
echo "$prefix$line"; \
done
This will give you a list like:
✔ stash@{0}: WIP on develop: 77a1a66 send 'social.share' message via 'view-req-relay'...
stash@{1}: WIP on bigcouch: 4bfa3af added couchdb filters...
And if you like it you can add it as a git alias like that:
git config --global --add alias.stash-list '!git stash list | while read line; do ref=${line%%:*}; prefix=$(test $(git diff $ref | wc -l) = "0" && echo "✔ " || echo " "); echo "$prefix$line"; done'
git stash-list
(tested with bash and zsh)
Just make a diff and you will see.
git diff HEAD stash@{0}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With