把当前工作现场“储藏”起来,等以后恢复现场后继续工作:
$ git stash
首先确定要在哪个分支上修复bug,假定需要在master
分支上修复,就从master
创建临时分支:
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 6 commits.
$ git checkout -b issue-101
Switched to a new branch 'issue-101'
修复完成后,切换到
master
分支,并完成合并,最后删除
issue-101
分支
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
$ git merge --no-ff -m "merged bug fix 101" issue-101
Merge made by the 'recursive' strategy.
readme.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
$ git branch -d issue-101
Deleted branch issue-101 (was cc17032).
刚才的工作现场存到哪去了?用
git stash list
命令看看:
$ git stash list
stash@{0}: WIP on dev: 6224937 add merge
用
git stash pop
,恢复的同时把stash内容也删了
你可以多次stash,恢复的时候,先用git stash list
查看,然后恢复指定的stash,用命令:
$ git stash apply stash@{0}