这甚至可能吗?我想要一个更简单的命令git stash pop stash@{13},stash@{13}只是last意味着"列表中的最后一个藏匿"或"最古老的藏匿".
我知道我可以创建一个别名git pop为git stash pop(我可以使用这样git pop stash@{13}),但我想简单的东西一样git pop last.我是否需要编写自己的脚本,或者有没有办法只使用git或别名?我主要使用Windows,但有时使用Linux.
建立@torek提供的提示,这可以让你得到你想要的存储的参考:
git reflog stash -- 2> /dev/null | tail -n 1 | cut -d ' ' -f 2 | cut -d ':' -f 1
Run Code Online (Sandbox Code Playgroud)
将--确保你正在寻找一个版本,而不是一个路径.该2> /dev/null禁止显示错误的情况下有没有藏匿.
避免使用的替代方法cut(由@torek再次建议)是:
git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1
Run Code Online (Sandbox Code Playgroud)
因此,您可以像这样设置别名:
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)"
Run Code Online (Sandbox Code Playgroud)
要么:
git config alias.pop-last "! git stash pop $(git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1)"
Run Code Online (Sandbox Code Playgroud)
No stash found.如果没有找到,这些命令中的任何一个都会给你一个很好的错误.
我已经测试过,这可以在Windows上的Git Bash提示符下运行.(它也适用于Linux.)