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都是 ...
随机推荐
- OpenCV和Boost C++库的安装
关于一般的安装步骤,此博客给出了详细的OpenCV的安装.一个步骤也不要落下,应该是不会出问题的. 主要的坑在Boost. 不知什么原因,我的电脑装boost_1_62_0-msvc-14.0-64, ...
- itoa()函数和sprintf()函数
itoa()函数 itoa 为c语言的一个函数.itoa 函数是一个广泛应用的,从非标准扩展到标准的C语言.它不能被移植,因为它不是标准定义下的C语言,但是,编译器通常在一个不遵循程式标准的模式下允许 ...
- (2).net web api 请求方式与参数
一.GET 二.POST 如果方法名前缀不带GET 默认为POST请求方法 1.无参数 2.带一个参数 客户端请求时,名称必须为空,不能是dictCategory.不是空的话,会返回空数据 [ ] 3 ...
- (11)oracle触发器
触发器是特殊的存储过程. 每当一个特定的数据操作语句(inster,update,delete)在指定的表上触发时,Oracle自动的地执行触发器中定义的语句序列. create trigger 触发 ...
- Properties文件工具读取类
import java.io.IOException;import java.io.InputStream;import java.util.Properties; public class Comm ...
- 洛谷—— P3908 异或之和
https://www.luogu.org/problemnew/show/P3908 题目描述 求1 \bigoplus 2 \bigoplus\cdots\bigoplus N1⨁2⨁⋯⨁N 的值 ...
- H-Index II -- LeetCode
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- [Contest20180418]数学竞赛
题意:初始时$x=0$(长度),当$x$为长度时,你可以把$x$变成$\sin^{-1}x,\cos^{-1}x,\tan^{-1}x$之一($x$变为角度),若$x$为角度,你可以把$x$变成$\s ...
- 队列 LinkedBlockingQueue
1 api java.util.concurrent包下的新类.LinkedBlockingQueue就是其中之一,是一个阻塞的线程安全的队列,底层采用链表实现. Li ...
- Jenkins配置Publish Junit test result report(转)
参考这篇文章:http://www.yiibai.com/jenkins/jenkins_unit_testing.html 插件:JUnit Plugin