Git--公司bug解决篇

  作为程序员,我们时常遇到这样的场景,公司的产品上线了,程序员们美滋滋的开始开发新功能希望得到更多的流量。这时候,公司上线的产品发生了很严重的bug,可是我们已经在这个bug的基础上将新功能开发了一半怎么办?

这时候就要用到Git的bug解决方案。

方案一:stash

stash用于将工作区发生变化的所有文件获取临时存储在“某个地方”,将工作区还原当前版本未操作前的状态;stash还可以将临时存储在“某个地方”的文件再次拿回到工作区。

acBook-Pro-:pondo gaoshengyue$ vim app01/views.py             # 开发灭霸功能,刚开发到一半

MacBook-Pro-:pondo gaoshengyue$ git status    #查看一下状态
On branch master
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: app01/views.py no changes added to commit (use "git add" and/or "git commit -a") MacBook-Pro-:pondo gaoshengyue$ git stash # 将开发到一半的灭霸功能,临时存储到“某个地方”
Saved working directory and index state WIP on master: 0972f4b 复仇者联盟上线
HEAD is now at 0972f4b 复仇者联盟上线 MacBook-Pro-:pondo gaoshengyue$ git status # 工作区回到当前版本未做任何操作前
On branch master
nothing to commit, working tree clean
###回滚
MacBook-Pro-:pondo gaoshengyue$ vim pondo/settings.py # 紧急修复bug
MacBook-Pro-:pondo gaoshengyue$ git status
On branch master
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: pondo/settings.py
no changes added to commit (use "git add" and/or "git commit -a") MacBook-Pro-:pondo gaoshengyue$ git add . # 添加到修改bug的代码到暂存状态
MacBook-Pro-:pondo gaoshengyue$ git commit -m '紧急修复bug' # 提交修复Bug的代码到分支
[master 1300d33] 紧急修复bug
file changed, insertion(+) MacBook-Pro-:pondo gaoshengyue$ git stash pop # 将开发到一半的灭霸功能从“某个地方”再次拿会工作区继续开发
On branch master
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: app01/views.py no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{} (059d78ca8fa204f9559bd3ce0ae76235969b4301)

特别的:执行 git stash pop 命令时,可能会遇到冲突,因为在紧急修复bug的代码和通过stash存储在“某个地方”的代码会有重合部分,所以执行 git stash pop 时候就会出现冲突,有冲突解决冲突即可。

a. 原来内容:
from django.shortcuts import render,HttpResponse def index(request):
return render(request,'index.html') def africa(request):
return HttpResponse('复仇者联盟') b. 开发到一半直播功能:
from django.shortcuts import render,HttpResponse def index(request):
return render(request,'index.html') def africa(request):
return HttpResponse('复仇者联盟') def live(request):
print('灭霸开发到一半')
return HttpResponse('....') c. 执行git stash,回到当前版本未修改状态:
from django.shortcuts import render,HttpResponse def index(request):
return render(request,'index.html') def africa(request):
return HttpResponse('复仇者联盟') d. 修复Bug并提交:
from django.shortcuts import render,HttpResponse def index(request):
return render(request,'index.html') def africa(request):
return HttpResponse('复仇者联盟金刚狼') e. 继续开发直播功能 git stash pop,此时会出现冲突:
MacBook-Pro-:pondo gaoshengyue$ git stash pop
Auto-merging app01/views.py
CONFLICT (content): Merge conflict in app01/views.py 表示app01/views.py存在冲突需要解决,此时文件内容为: from django.shortcuts import render,HttpResponse def index(request):
return render(request,'index.html') def africa(request):
<<<<<<< Updated upstream: # 修复Bug时更改的内容
return HttpResponse('复仇者联盟金刚狼')
======= # 修复Bug前正在开发新功能时的内容
return HttpResponse('复仇者联盟') def live(request):
print('灭霸刚开发到一半')
return HttpResponse('灭霸')
>>>>>>> Stashed changes 需要自行解决冲突,然后继续开发,如: from django.shortcuts import render,HttpResponse def index(request):
return render(request,'index.html') def africa(request): return HttpResponse('复仇者联盟金刚狼') def live(request):
print('灭霸刚开发到一半')
return HttpResponse('灭霸')

stash相关常用命令:

  • git stash             将当前工作区所有修改过的内容存储到“某个地方”,将工作区还原到当前版本未修改过的状态
  • git stash list        查看“某个地方”存储的所有记录
  • git stash clear     清空“某个地方”
  • git stash pop       将第一个记录从“某个地方”重新拿到工作区(可能有冲突)
  • git stash apply     编号, 将指定编号记录从“某个地方”重新拿到工作区(可能有冲突)
  • git stash drop      编号,删除指定编号的记录

方案二:branch

分支学习:branch称为分支,默认仅有一个名为master的分支。一般开发新功能流程为:开发新功能时会在分支dev上进行,开发完毕后再合并到master分支。

MacBook-Pro-:pondo gaoshengyue$ git branch dev                 # 创建新分支,即:拷贝一份当前所在分支代码到新分支
MacBook-Pro-:pondo gaoshengyue$ git checkout dev # 切换到dev分支
MacBook-Pro-:pondo gaoshengyue$ vim app01/views.py # 开发功能
MacBook-Pro-:pondo gaoshengyue$ git status # 查看状态,即:在dev分支修改了app01/views.py文件
On branch dev
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: app01/views.py no changes added to commit (use "git add" and/or "git commit -a")
MacBook-Pro-:pondo gaoshengyue$ git add . # 将修改文件添加到版本库的暂存区
MacBook-Pro-:pondo gaoshengyue$ git commit -m '新功能开发完毕' # 将暂存区的内容提交到当前所在分支,即:dev分支
[dev 32b40cd] 新功能开发完毕
file changed, insertions(+)
MacBook-Pro-:pondo gaoshengyue$ git checkout master # 切换回master分支
Switched to branch 'master'
MacBook-Pro-:pondo gaoshengyue$ git merge dev # 将dev分支内容合并到master分支
Updating 0972f4b..32b40cd
Fast-forward
app01/views.py | ++
file changed, insertions(+)

一般流程示例(上图)

按照分支的思路,如果我们在公司产品上线遇到bug的时候,就可以这么来做:

MacBook-Pro-:pondo gaoshengyue$ git branch                     # 当前在master分支
* master MacBook-Pro-:pondo gaoshengyue$ git branch dev # 创建dev分支用于开发新功能 MacBook-Pro-:pondo gaoshengyue$ git checkout dev # 切换到dev分支
Switched to branch 'dev' MacBook-Pro-:pondo gaoshengyue$ vim app01/views.py # 开发新功能到一半,需要紧急修复Bug MacBook-Pro-:pondo gaoshengyue$ git add . MacBook-Pro-:pondo gaoshengyue$ git commit -m '新功能开发一半'
[dev b3ac2cb] 新功能开发一半
file changed, insertions(+) MacBook-Pro-:pondo gaoshengyue$ git checkout master # 切换回master分支
Switched to branch 'master' MacBook-Pro-:pondo gaoshengyue$ git branch bug # 创建bug分支 MacBook-Pro-:pondo gaoshengyue$ git checkout bug # 切换到bug分支
Switched to branch 'bug' MacBook-Pro-:pondo gaoshengyue$ vim pondo/settings.py # 修改bug MacBook-Pro-:pondo gaoshengyue$ git add . # 提交bug MacBook-Pro-:pondo gaoshengyue$ git commit -m '紧急修复bug' # 提交bug
[bug f42f386] 紧急修复bug
file changed, insertion(+), deletion(-) MacBook-Pro-:pondo gaoshengyue$ git checkout master # 切换会master
Switched to branch 'master' MacBook-Pro-:pondo gaoshengyue$ git merge bug # 将bug分支内容合并到master分支,表示bug修复完毕,可以上线
Updating 0972f4b..f42f386
Fast-forward
pondo/settings.py | +-
file changed, insertion(+), deletion(-) MacBook-Pro-:pondo gaoshengyue$ git checkout dev # 切换到dev分支,继续开发新功能
Switched to branch 'dev' MacBook-Pro-:pondo gaoshengyue$ vim app01/views.py # 继续开发其他一半功能 MacBook-Pro-:pondo gaoshengyue$ git add . # 提交新功能 MacBook-Pro-:pondo gaoshengyue$ git commit -m '继续开发完成' # 提交功能
[dev c0bfb27] 继续开发完成
file changed, insertion(+) MacBook-Pro-:pondo gaoshengyue$ git checkout master # 切换回master分支
Switched to branch 'master' MacBook-Pro-:pondo gaoshengyue$ git merge dev # 将dev分支合并到master分支
Merge made by the 'recursive' strategy.
app01/views.py | +++
file changed, insertions(+)

注意:git merge 时也可能会出现冲突,解决冲突的方式上述stash相同,即:找到冲突文件,手动修改冲突并提交。

branch相关常用命令:

  • git branch 分支名称             创建分支
  • git checkout 分支名称          切换分支
  • git branch -m 分支名称        创建并切换到指定分支
  • git branch                          查看所有分支
  • git branch -d 分支名称         删除分支
  • git merge 分支名称              将指定分支合并到当前分支

Git--Bug解决篇的更多相关文章

  1. dede留言板BUG解决

    dede留言板刷新后空白BUG解决 DEDE留言板验证码留空或者不正确返回空白页面的解决方法 解决方法如下进入文件/plus/guestbook.php 找到代码ShowMsg("验证码不正 ...

  2. git 提交解决冲突(转载)

    转载 git 提交解决冲突 http://www.cnblogs.com/qinbb/p/5972308.html   一:git命令在提交代码前,没有pull拉最新的代码,因此再次提交出现了冲突. ...

  3. git 命令(提高篇)的本质理解

    上一篇博客:[[git 命令(提高篇)的本质理解] (http://www.cnblogs.com/juking/p/7105744.html)]介绍了Git 的基础知识 -- 提交.分支以及在提交树 ...

  4. Git使用基础篇

    Git使用基础篇 前言 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体验到原来一个版 本控制工具可以对开发产生如此之多 ...

  5. Git使用基础篇(zz)

    Git使用基础篇 您的评价:          收藏该经验       Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体 ...

  6. 从零开始使用git第三篇:git撤销操作、分支操作和常见冲突

    从零开始使用git 第三篇:git撤销操作.分支操作和常见冲突 第一篇:从零开始使用git第一篇:下载安装配置 第二篇:从零开始使用git第二篇:git实践操作 第三篇:从零开始使用git第三篇:gi ...

  7. jenkins持续集成源码管理选项为None,构建失败找不到git.exe解决办法

    我的jenkins版本为Jenkins ver. 2.19.1 1.源码管理选项只有None的解决办法: 在插件管理中心,搜索对应的源码管理插件这里以git为例,搜索git plugin点击右下角的安 ...

  8. 百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法

    百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法 金刚 前端 ueditor 初始化 因项目中使用了百度编辑器——ueditor.整体来说性能还不错. 发现问题 我在做一个编辑页面 ...

  9. paip.c3p0 nullpointexcept 配置文件根路径读取bug 解决

    paip.c3p0 nullpointexcept 配置文件根路径读取bug 解决 windows ok linux犯错误... 查看loging, 初始化的时候儿jdbcurl,user,pwd都是 ...

随机推荐

  1. UVA 562 Dividing coins【01背包 / 有一堆各种面值的硬币,将所有硬币分成两堆,使得两堆的总值之差尽可能小】

    It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nic ...

  2. 51nod 1420 数袋鼠好有趣【贪心】

    1420 数袋鼠好有趣 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 有n只袋鼠.每只袋鼠的大小用一个整数表示. ...

  3. java的IO,AIO简单对比

    以下内容转载lzzzl Channel 通道 Buffer 缓冲区 Selector 选择器 其中Channel对应以前的流,Buffer不是什么新东西,Selector是因为nio可以使用异步的非堵 ...

  4. KDtree浅谈

    KDtree浅谈 1.对KDtree的理解 首先要知道$KDtree$的用处,$KDtree$是用来进行多维数点的,一般这些点都是在在而二维及二维以上,因为一维上的问题,我们基本都可以运用线段树来解决 ...

  5. APIO2018练习赛伪题解

    传送门:https://pcms.university.innopolis.ru/statements/org/apio/2018/practice/statements.pdf 主要就在于后面三道构 ...

  6. [BZOJ 1806] Miners 矿工配餐

    Link: BZOJ 1806 传送门 Solution: 为了使状态包含每个节点前所有必须的信息: 设$dp[i][a1][a2][b1][b2]$为配送到第$i$个,一厂前两个为$a1,a2$,二 ...

  7. Parse error: syntax error, unexpected end of file in *.php on line * 解决方法

    Parse error: syntax error, unexpected end of file in *.php on line * 解决方法   这篇文章主要介绍了PHP错误Parse erro ...

  8. linux之网络配置相关

    ubuntu的网络配置文件在 /etc/network/intrfaces; suse的网络配置在          /etc/sysconfig/network/下面,每个网卡一个配置文件. int ...

  9. Git:fatal: The remote end hung up unexpectedly

    一.配置公共密钥 https://help.github.com/articles/generating-ssh-keys/ 二.设置缓冲值(push文件较大时导致错误) \.git\config [ ...

  10. docker 安装nginx并挂载配置文件和www目录以及日志目录

    ---恢复内容开始--- 一 首先 docker pull nginx 二 docker run --name myNginx -d -p 80:80 -v e:/docker/nginx/www:/ ...