Skip to content

Git Stash Pop

一句话解释

git stash pop 把最近暂存的变更重新应用到工作树并从暂存列表移除。

用大白话说

git stash pop 把最近暂存的变更(stash@{0})重新应用到工作目录,然后删除该暂存条目。它是 git stash 的逆操作——stash 保存未提交工作,pop 恢复。这是切换上下文再回来的常用方式。若应用暂存会与当前变更冲突,pop 尽量应用并把冲突留在工作树供你解决。仅在 apply 失败时保留暂存条目;成功则删除。用 git stash apply 恢复而不删除,以防你想在别处应用同一暂存。可用 git stash pop stash@{2} 弹出特定暂存。若在错误分支弹出或冲突严重,可用 git checkout . 小心撤销或从 reflog 恢复暂存。暂存是栈——push 与 pop——但条目在垃圾回收前也可经 reflog 访问。

示例

bash
# Save current work, switch context, come back
echo "wip" >> file.txt
git stash            # saved as stash@{0}
git status           # working tree clean
git checkout main    # do something else
git checkout feature
git stash pop        # reapply and drop stash@{0}
# file.txt now has "wip" again

# Apply a specific stash without dropping
git stash apply stash@{1}

stash 保存未提交工作;pop 恢复栈顶并删除。apply 恢复而不删除。冲突时保留暂存。

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表