Bug分支

软件开发中,bug就像家常便饭一样。有了bug就需要修复,在Git中,由于分支是如此的强大,所以,每个bug都可以通过一个新的临时分支来修复,修复后,合并分支,然后将临时分支删除。
1. 查看工作区状态
$ git status
On branch master
Your branch is ahead of 'origin/master' by 6 commits.
  (use "git push" to publish your local commits)
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
no changes added to commit (use "git add" and/or "git commit -a")

2. 储藏当前工作现场“储藏”起来:
$ git stash
Saved working directory and index state WIP on master: 07dd582 merge no-ff
HEAD is now at 07dd582 merge no-ff
$ git status
On branch master
Your branch is ahead of 'origin/master' by 6 commits.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

3. 创建bug分支
$ git checkout -b bug1
Switched to a new branch 'bug1'

4. 修复bug,并提交代码
$ git status
On branch bug1
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
no changes added to commit (use "git add" and/or "git commit -a")
$ git add readme.txt
$ git commit -m "fixed bug1"
[bug1 95d8722] fixed bug1
 1 file changed, 1 insertion(+), 1 deletion(-)

5. 切换回master分支,合并分支
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 6 commits.
  (use "git push" to publish your local commits)
$ git merge bug1
Updating 07dd582..95d8722
Fast-forward
 readme.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

6. 删除bug1分支
$ git branch -d bug1
Deleted branch bug1 (was 95d8722).

7. 查看储藏的现场
$ git stash list
stash@{0}: WIP on master: 07dd582 merge no-ff

8. 恢复现场
$ git stash apply stash@{0}
Auto-merging readme.txt
On branch master
Your branch is ahead of 'origin/master' by 7 commits.
  (use "git push" to publish your local commits)
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
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash list
stash@{0}: WIP on master: 07dd582 merge no-ff
另一种方式是用git stash pop恢复现场,恢复的同时把stash内容也删了
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

morris131

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值