别名:`git pop last`,用于`git stash pop [last stash on the list]`
Alias: `git pop last`, for `git stash pop [last stash on the list]`
这可能吗?我想要一个更简单的 git stash pop stash@{13}
命令,其中 stash@{13}
只是 last
意思是 "the last stash on the list" 或 "the oldest stash".
我知道我可以为 git stash pop
创建别名 git 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
--
确保您正在寻找修订版而不是路径。如果没有存储,2> /dev/null
会抑制错误。
避免使用 cut
的替代方法(@torek 再次建议)是:
git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1
因此,您可以这样设置您的别名:
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)"
或者:
git config alias.pop-last "! git stash pop $(git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1)"
如果找到 none,这些命令中的任何一个都会给你一个很好的错误 No stash found.
。
我已经测试过,这在 Windows 的 Git Bash 提示中有效。 (它应该也适用于 Linux。)
这可能吗?我想要一个更简单的 git stash pop stash@{13}
命令,其中 stash@{13}
只是 last
意思是 "the last stash on the list" 或 "the oldest stash".
我知道我可以为 git stash pop
创建别名 git 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
--
确保您正在寻找修订版而不是路径。如果没有存储,2> /dev/null
会抑制错误。
避免使用 cut
的替代方法(@torek 再次建议)是:
git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1
因此,您可以这样设置您的别名:
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)"
或者:
git config alias.pop-last "! git stash pop $(git log --walk-reflogs --format=%gd stash -- 2> /dev/null | tail -n 1)"
如果找到 none,这些命令中的任何一个都会给你一个很好的错误 No stash found.
。
我已经测试过,这在 Windows 的 Git Bash 提示中有效。 (它应该也适用于 Linux。)