Git--Bug解决篇
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解决篇的更多相关文章
- dede留言板BUG解决
dede留言板刷新后空白BUG解决 DEDE留言板验证码留空或者不正确返回空白页面的解决方法 解决方法如下进入文件/plus/guestbook.php 找到代码ShowMsg("验证码不正 ...
- git 提交解决冲突(转载)
转载 git 提交解决冲突 http://www.cnblogs.com/qinbb/p/5972308.html 一:git命令在提交代码前,没有pull拉最新的代码,因此再次提交出现了冲突. ...
- git 命令(提高篇)的本质理解
上一篇博客:[[git 命令(提高篇)的本质理解] (http://www.cnblogs.com/juking/p/7105744.html)]介绍了Git 的基础知识 -- 提交.分支以及在提交树 ...
- Git使用基础篇
Git使用基础篇 前言 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体验到原来一个版 本控制工具可以对开发产生如此之多 ...
- Git使用基础篇(zz)
Git使用基础篇 您的评价: 收藏该经验 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体 ...
- 从零开始使用git第三篇:git撤销操作、分支操作和常见冲突
从零开始使用git 第三篇:git撤销操作.分支操作和常见冲突 第一篇:从零开始使用git第一篇:下载安装配置 第二篇:从零开始使用git第二篇:git实践操作 第三篇:从零开始使用git第三篇:gi ...
- jenkins持续集成源码管理选项为None,构建失败找不到git.exe解决办法
我的jenkins版本为Jenkins ver. 2.19.1 1.源码管理选项只有None的解决办法: 在插件管理中心,搜索对应的源码管理插件这里以git为例,搜索git plugin点击右下角的安 ...
- 百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法
百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法 金刚 前端 ueditor 初始化 因项目中使用了百度编辑器——ueditor.整体来说性能还不错. 发现问题 我在做一个编辑页面 ...
- paip.c3p0 nullpointexcept 配置文件根路径读取bug 解决
paip.c3p0 nullpointexcept 配置文件根路径读取bug 解决 windows ok linux犯错误... 查看loging, 初始化的时候儿jdbcurl,user,pwd都是 ...
随机推荐
- Number of Connected Components in an Undirected Graph -- LeetCode
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- POJ 2482 Stars in Your Window 离散化+扫描法 线段树应用
遇见poj上最浪漫的题目..题目里图片以上几百词为一篇模板级英文情书.这情感和细腻的文笔深深地打动了我..不会写情书的童鞋速度进来学习.传送门 题意:坐标系内有n个星星,每个星星都有一个亮度c (1& ...
- Java 根据年月日精确计算年龄
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Created b ...
- 一种用XAML写Data Converter的方式
在WPF程序中,数据绑定是非常常用的手段.伴随着数据绑定,我们通常还需要编写一些Converter.而编写Converter是一件非常枯燥的事情,并且大量的converter不容易组织和维护. 今天在 ...
- delphi 浮点数转换成十六进制字符串的方法
我们在研究封包技术时,经常会碰到将浮点数转换成十六进制形式.比如在游戏中人物的座标,经常就用浮点数来表示.怎么将浮点数转换成十六进制字符串形式呢?下面我将写出其在DELPHI中的方法. 先 ...
- CSS背景属性background
background属性是所有背景属性的缩写: 以下是这些背景属性: background-color:背景颜色 你可以通过颜色名称(red/green/blue)来设置 也可以用十六进制(#fff/ ...
- 【spring data jpa】【mybatis】通过反射实现 更新/保存 实体的任意字段的操作
代码如下: //代码示例:例如保存时,传入下面两个字段 String filed;String content; //User代表要更新的实体,user即本对象 //filed代表要更改的字段,例如u ...
- SQL 存储过程(转帖摘录)
篇一: 创建存储过程 Create Proc dbo.存储过程名 存储过程参数 AS 执行语句 RETURN 执行存储过程 GO *********** ...
- Makefile文件的使用
编译程序: vi Makefile exe:a.c b.c gcc a.c b.c -o exe clean: rm exe 保存并退出: 这里exe:a.c b.c面的exe称为目标:a.c b.c ...
- spring boot 缺点优点?
作者:八面山人链接:https://www.zhihu.com/question/39483566/answer/246333825来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

