git分支修复bug
2015-04-26 11:26
316 查看
当你接到一个修复一个代号101的bug的任务时,很自然地,你想创建一个分支
并不是你不想提交,而是工作只进行到一半,还没法提交,预计完成还需1天时间。但是,必须在两个小时内修复该bug,怎么办?
幸好,Git还提供了一个
现在,用
首先确定要在哪个分支上修复bug,假定需要在
现在修复bug,需要把“Git is free software ...”改为“Git is a free software ...”,然后提交:
修复完成后,切换到
太棒了,原计划两个小时的bug修复只花了5分钟!现在,是时候接着回到
工作区是干净的,刚才的工作现场存到哪去了?用
工作现场还在,Git把stash内容存在某个地方了,但是需要恢复一下,有两个办法:
一是用
另一种方式是用
再用
你可以多次stash,恢复的时候,先用
修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除;
当手头工作没有完成时,先把工作现场
issue-101来修复它,但是,等等,当前正在
dev上进行的工作还没有提交:
$ git status # On branch dev # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: hello.py # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: readme.txt #
并不是你不想提交,而是工作只进行到一半,还没法提交,预计完成还需1天时间。但是,必须在两个小时内修复该bug,怎么办?
幸好,Git还提供了一个
stash功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作:
$ git stash Saved working directory and index state WIP on dev: 6224937 add merge HEAD is now at 6224937 add merge
现在,用
git status查看工作区,就是干净的(除非有没有被Git管理的文件),因此可以放心地创建分支来修复bug。
首先确定要在哪个分支上修复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'
现在修复bug,需要把“Git is free software ...”改为“Git is a free software ...”,然后提交:
$ git add readme.txt $ git commit -m "fix bug 101" [issue-101 cc17032] fix bug 101 1 file changed, 1 insertion(+), 1 deletion(-)
修复完成后,切换到
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).
太棒了,原计划两个小时的bug修复只花了5分钟!现在,是时候接着回到
dev分支干活了!
$ git checkout dev Switched to branch 'dev' $ git status # On branch dev nothing to commit (working directory clean)
工作区是干净的,刚才的工作现场存到哪去了?用
git stash list命令看看:
$ git stash list stash@{0}: WIP on dev: 6224937 add merge
工作现场还在,Git把stash内容存在某个地方了,但是需要恢复一下,有两个办法:
一是用
git stash apply恢复,但是恢复后,stash内容并不删除,你需要用
git stash drop来删除;
另一种方式是用
git stash pop,恢复的同时把stash内容也删了:
$ git stash pop # On branch dev # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: hello.py # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: readme.txt # Dropped refs/stash@{0} (f624f8e5f082f2df2bed8a4e09c12fd2943bdd40)
再用
git stash list查看,就看不到任何stash内容了:
$ git stash list
你可以多次stash,恢复的时候,先用
git stash list查看,然后恢复指定的stash,用命令:
$ git stash apply stash@{0}
小结
修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除;当手头工作没有完成时,先把工作现场
git stash一下,然后去修复bug,修复后,再
git stash pop,回到工作现场。
相关文章推荐
- git 新建分支修复bug学习笔记
- Git中的bug修复分支
- git 分配员工到分支上修复bug
- 使用Git分支开发新特性或修复Bug与使用Git分支开发新特性或修复Bug
- Android关于从git检出分支到本地编译时报aapt.AaptException Failed to crunch file的bug修复
- Git 修复 bug 切换分支时,如何保存修改过的代码(即如何保存现场)?
- Git 通过Tag标签回退版本修复bug
- Git Stash用法,方便临时处理bug时随时切换分支而不丢失修改
- Git学习笔记(二)分支管理与合并及Bug分支
- git分支管理之Bug分支
- Git Bug分支
- GIT 分支管理:分支管理策略、Bug分支、Feature分支
- Git之修复Bug流程
- Git学习系列(七)Bug和Feature分支管理详解
- git 分支修改bug应用场景
- Git_Bug分支
- (转)Git Stash用法,方便临时处理bug时随时切换分支而不丢失修改
- 五、git学习之——分支管理策略、Bug分支、feature分支、多人协作
- Git-10_bug分支
- Git 使用教程(六):Bug分支和Feature分支