美文网首页
Git分支管理—Bug分支

Git分支管理—Bug分支

作者: by小杰 | 来源:发表于2017-01-25 14:07 被阅读25次

应用场景:
当你接到一个修复代号101的bug的任务时,很自然地,你想创建一个分支issue-101来修复它,但是,等等,当前正在dev上进行的工作还没有提交。并不是你不想提交,而是工作只进行到一半,还没法提交,预计完成还需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).```

现在,是时候接着回到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 | 分支管理

    git分支管理 主分支 功能分支 - feature 预发布分支 - release 修补bug分支 - fixbug

  • Git分支管理—Bug分支

    应用场景:当你接到一个修复代号101的bug的任务时,很自然地,你想创建一个分支issue-101来修复它,但是,...

  • git常用命令

    分支管理 git 切换分支 git 查看远程分支 git 查看本地分支 git 创建本地分支 git 删除本地分支...

  • git分支管理之 - Bug分支

    软件开发中,bug就像家常便饭一样。有了bug就需要修复,在Git中,由于分支是如此的强大,所以,每个bug都可以...

  • (4.4) git分支管理-Bug分支

    小结 修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除; 当手头工作没有完成时,先把工作现场...

  • git工作流

    git工作流 1.Gitflow核心分支: master,dev可能还会有: 功能分支,bug修复分支,预发布分支...

  • git工作流程

    1.Git flow 核心分支:master,dev可能还会有:功能分支,bug修复分支,预发布分支 2.gith...

  • git提交代码规范管理

    GIT分支管理 git远程分支主要包括:master develop fixbugmaster:整个项目主分支,...

  • 2021-11-30

    一、分支管理 1、创建分支 git branch 2、查看分支 git branch...

  • 分支管理

    本节内容: 创建与合并分支 解决冲突 分支管理策略 bug分支 Feature分支 多人协作

网友评论

      本文标题:Git分支管理—Bug分支

      本文链接:https://www.haomeiwen.com/subject/mzutittx.html