git Bug分支

现将目前的分支工作现场“储藏”起来。

$ git stash

stash功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作。

每个bug都可以通过一个新的临时分支来修复,修复后,合并分支,然后将临时分支删除。

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

$ git checkout master
$ git checkout -b issue-101

修复bug,然后提交:

$ git add readme.txt 
$ git commit -m "fix bug 101"

修复完成后,切换到master分支,并完成合并,最后删除issue-101分支:

$ git checkout master
$ git merge --no-ff -m "merged bug fix 101" issue-101
$ git branch -d issue-101

接着回到dev分支干活:

$ git checkout dev
$ git status
$ git stash list

工作现场还在,Git把stash内容存在某个地方了,但是需要恢复一下,有两个办法:

一是用git stash apply恢复,但是恢复后,stash内容并不删除,你需要用git stash drop来删除;

另一种方式是用git stash pop,恢复的同时把stash内容也删了:

再用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,回到工作现场。

猜你喜欢

转载自www.cnblogs.com/mengfangui/p/8944225.html
今日推荐