git stash

使用背景:

在一个分支开发新功能,还没开发完毕,做到一半时有反馈紧急bug需要处理,但是新功能开发了一半又不想提交。

相关命令:

命令名作用
git stash隐藏当前的工作现场, 此时, git status的结果是 clean
git stash list查看所有隐藏, 每一行的冒号前面的字符串就是标识此隐藏的id
git stash apply重新显示标识为 id 的隐藏
git stash dropgit apply恢复隐藏后, 需要手动删除 list 列表中的记录
git stash pop恢复最新的进度到工作区
git stash pop stash@[stash_id]恢复指定的进度到工作区

若我们开发时候使用git status list如下:

stash@{0}: On fix_grade_bug2: 8888
stash@{1}: On fix_grade_bug9: 999
stash@{2}: On fix_grade_bug6: 666

若想应用执行版本:

git stash apply n

n为括号中的序号

这在不同的分支开发中都想存储内容时很有效,因为可以按需恢复。