Git的bug分支
上一篇提到却换或者新建分支时,当前分支必须提交或者保存
Please commit your changes or stash them before you switch branches.
此时工作只进行到一半,还没法提交,但又必须保存了去修改bug,此时Git还提供了一个stash功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作:
$ git stash
首先确定要在哪个分支上修复bug,假定需要在dev分支上修复bug001,就从bug创建临时分支:
$ git checkout dev
Switched to branch 'dev'
Your branch is ahead of 'one/dev' by 1 commits.
$ git checkout -b bug-001
Switched to a new branch 'bug-001'
修改完成后
$ git add 1.txt
$ git commit -m "xiu gai le bug 001"
[bug-001 cc18202] xiu gai le bug 001
修复提交完成后,切换到dev分支,并完成合并,最后删除bug-001分支:
$ git checkout dev
Switched to branch 'master'
Your branch is ahead of 'one/dev' by 1 commits.
$ git merge --no-ff -m "merged bug001"
bug-001Merge made by the 'recursive' strategy.
1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
$ git branch -d bug-001
Deleted branch bug-001 (was cc18202).
现在就是切回原来未完成的分支了
$ git checkout develop
Switched to branch 'develop'
$ git stash list//用git stash list命令查看工作现场保存地方
stash@{0}: WIP on dev: 6224937 add merge
恢复工作现场,有两个办法:
一:用git stash apply恢复,但是恢复后,stash内容并不删除,你需要用git stash drop来删除;
二:用git stash pop,恢复的同时把stash内容也删了:
可以多次stash,恢复的时候,先用git stash list查看,然后恢复指定的stash,用命令:
$ git stash apply stash@{0}