问题
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.
回答1:
Just make a diff and you will see.
git diff HEAD stash@{0}
回答2:
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)
来源:https://stackoverflow.com/questions/7962942/how-can-you-tell-if-a-git-stash-is-no-longer-required