小结
-
修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除;
-
当手头工作没有完成时,先把工作现场git stash一下,然后去修复bug,修复后,再git stash pop,回到工作现场。
正文
当前正在dev上进行的工作还没有提交,但要先建立一个issue-101分支来修复BUG:

Git提供了一个stash功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作:



首先确定要在哪个分支上修复bug,假定需要在master分支上修复,就从master创建临时分支:

现在修复bug,需要把“Git is free software ...”改为“Git is a free software ...”,然后提交:
修复完成后,切换到master分支,并完成合并,最后删除issue-101分支:

- 现在,接着回到dev分支干活。
- 工作区是干净的,刚才的工作现场存到哪去了?用git stash list命令看看:
3>工作现场还在,Git把stash内容存在某个地方了,但是需要恢复一下,有两个办法:一是用git stash apply
恢复,但是恢复后,stash内容并不删除,你需要用git stash drop
来删除;另一种方式是用git stash pop
,恢复的同时把stash内容也删了:

再用
git stash list
查看,就看不到任何stash内容了:

**可以多次stash,恢复的时候,先用
git stash list
查看,然后恢复指定的stash,用命令:git stash apply stash@{0}
网友评论