目录
[2.1 使用之前,先简单了解下 git stash 干了什么:](#2.1 使用之前,先简单了解下 git stash 干了什么:)
[2.2 git stash 相关命令](#2.2 git stash 相关命令)
[2.3 使用流程](#2.3 使用流程)
[1. 执行 `git stash`](#1. 执行 git stash
)
[2. 查看刚才保存的工作进度 `git stash list`](#2. 查看刚才保存的工作进度 git stash list
)
[3. 这时候在看分支已经是干净无修改的(改动都有暂存到 stash)](#3. 这时候在看分支已经是干净无修改的(改动都有暂存到 stash))
[4. 现在就可以正常切换到目标分支,进行相应操作](#4. 现在就可以正常切换到目标分支,进行相应操作)
[5. 其他分支处理完成,再切回来使用刚才的 stash, 还是先查看 暂缓列表](#5. 其他分支处理完成,再切回来使用刚才的 stash, 还是先查看 暂缓列表)
[6. 选择使用暂缓 `git stash apply n`](#6. 选择使用暂缓 git stash apply n
)
一、背景
我们经常会遇到这样的情况:
在一个分支开发新功能,还没开发完毕,做到一半时有反馈紧急bug需要处理,但是新功能开发了一半又不想提交。
这时就可以使用 git stash
二、使用
2.1 使用之前,先简单了解下 git stash 干了什么:
它会保存当前工作进度,会把暂存区和工作区的改动保存到一个未完结变更的堆栈中;执行完这个命令后,在运行 git status
命令,就会发现当前是一个干净的工作区,没有任何改动。
git stash
是本地的,不会上传到服务器上;- 可以使用
git stash save 'message...'
添加一些注释。
2.2 git stash 相关命令
2.3 使用流程
一般先使用 git stash list 查看有没有已经 stash 的记录,避免和自己的混淆,到时候使用时不知道是哪条记录


查看有无用的 list,可以先使用 git stash drop n 删除,直到 list 为空
1. 执行 `git stash`

默认是不带注释的,想要后面看的更清楚该 stash 是存储的什么,可以如下操作:
执行 `git stash save "commend"`

2. 查看刚才保存的工作进度 `git stash list`
保存注释的长这样:

可以看到 stash@{0} 是刚才保存的
3. 这时候在看分支已经是干净无修改的(改动都有暂存到 stash)

4. 现在就可以正常切换到目标分支,进行相应操作
5. 其他分支处理完成,再切回来使用刚才的 stash, 还是先查看 暂缓列表

6. 选择使用暂缓 `git stash apply n`
注:n 是序号,如下图红色箭头指示

