Changing @torek's prompts will give you a message saying what you want:
git reflog stash -- 2> /dev/null | tail -n 1 | cut -d ' ' -f 2 | cut -d ':' -f 1
--ensures that you are looking for a version, not a path. 2> /dev/nullsuppresses errors if there are no delays.
An alternative that avoids the use of cut(again suggested by @torek) is:
git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1
Thus, you can set your alias as follows:
git config alias.pop-last "! git stash pop $(git reflog stash -- 2> /dev/null | tail -n 1 | cut -d ' ' -f 2 | cut -d ':' -f 1)"
Or:
git config alias.pop-last "! git stash pop $(git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1)"
Any of these commands will give you a good mistake No stash found.if it is not found.
I tested and it works at the Git Bash prompt on Windows. (It should also work on Linux.)
source
share