Skip to content

Stash

一句话解释

Stashing temporarily 保存你的 uncommitted 更改 in stack, cleaning 你的工作 directory 所以你 能切换上下文.

用大白话说

git stash shelves 你的 uncommitted 更改 (两者都 staged and unstaged) and restores 工作 directory 到最后 committed 状态. 更改是 保存 in stash stack and 能是 restored later 使用 git stash pop.

Stashing is the solution to "I 是 in 中间的某事但 I 需要到切换分支 urgently." Instead of committing half-finished work (which creates a junk commit), you stash it, switch branches, do what you need, switch back, and pop the stash to resume.

You can have multiple stashes in a stack. git stash 列表 shows all stashes, git stash apply restores without removing, git stash drop removes without restoring, and git stash pop does both (apply + drop).

示例

bash
# Stash current work
git stash

# Switch branches and do something urgent
git checkout main
# ... fix a bug ...
git checkout feature

# Restore your stashed work
git stash pop

Stash 保存更改 temporarily; pop restores 它们.

相关术语

相关资源

相关课程

解读错误信息

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

查看错误

← 返回术语表