Smiling & Weeping

                 ---- 我渴望你的在场,又渴望你的缺席,你终究是我深藏的借口

第六章 GitFlow工作流实战

6.0 引言

在实际项目开发工作中,常常会有自测、联调、提测、线上紧急修复等多工作环节,对应可能需要本地、内测、开发、测试、生产等多环境部署代码的需求,对应每个环节会产生不同的分支;本⽂将从Git-Flow模型原理出发,通过命令行演示实际可操作⼿段并进⾏总结,最终希望Git-Flow在实际项⽬中应⽤起来,从⽽⾼效完成代码开发、版本管理等实际⼯作。

(注:不同的公司或者不同的项目的GitFlow工作流模型标准也不同,具体以实际应用为准;本文提供的为常用模板,较为全面和通用,建议多加练习,达到熟练掌握的程度)

6.1 深⼊理解Git-Flow⼯作流模型原理

  • Git-Flow模型解决什么问题?

    为了解决实际项⽬中代码开发、代码测试、bug修复、版本发布等⼀系过程列严重耦合从⽽产⽣各种问题,如冲突过度、版本混乱。

  • Git-Flow模型⼜是如何解决上述问题的呢?

    基于Git定义5种类型的分⽀,各分⽀严格定义其指责、起⽌点等,从⽽使开发、测试、发版等过程有条不紊进⾏。

6.1.1 Git-Flow流程图

该流程图完整描述Git-Flow模型处理过程,当我们深⼊理解各分⽀,然后结合项⽬阶段与⾃身的⻆⾊(开发/测试/项⽬经理),就会发现每个角色在某个阶段需要关注的可能也就⼀两个分⽀,⽐如在开发阶段,开发⼈员只需关注⾃⼰的新功能分⽀(Feature分支);release阶段,测试⼈员和开发⼈员都只需关注Release分⽀,各⾃的职责有所差异⽽已;具体如下图(建议读者动手手绘一遍该流程图以便于加深理解):

6.1.2 Git-Flow各分⽀的说明

分⽀名称 作⽤ ⽣命周期 提交or合并 起⽌点
Feature分⽀ ⽤于某个功能的 临时分 ⽀、开发 阶段 可提交代码 由Develop分⽀产⽣, 最终合并到Develop 分⽀
Develop分⽀ 记录历史开发功 能 贯穿整个 项⽬ 不能提交,由Feature分 ⽀、Bugfix分⽀、Release 分⽀、Hotfix分⽀合并代码 整个项⽬
Release分⽀ ⽤于本次Release 如⽂档、测试、 bug修复 临时分 ⽀、发版 阶段 可提交代码 由Develop分⽀产⽣, 最终合并到Develop 分⽀和Master分支
Hotfix分⽀ ⽤于解决线上bug 临时分 ⽀、紧急 修复阶段 可提交代码 由Master分⽀产⽣, 最终合并到Develop 分⽀和Master分支
Master(Production) 分⽀ 记录历史发布版 本 贯穿整个 项⽬ 不能提交,由Release、Hotfix分⽀合并代码 整个项⽬

6.1.3 不同⻆度理解各分⽀

  • ⽣命周期

    Master分⽀和Develop分⽀贯穿项⽬;其他分⽀均为承担特定指责的临时分⽀。

  • 项⽬阶段

    开发阶段主要涉及Feature分⽀、Develop分⽀; 发布阶段 主要涉及Release分⽀、Production分⽀、Develop分⽀; 紧急修复阶段 主要涉及Hotfix分⽀、Production分⽀、Develop分⽀。

  • 成员关注点

    开发⼈员 关注Develop分⽀、Feature分⽀以及特殊阶段关注Hotfix、Release分⽀的bug修复; 测试⼈员 关注 Release分⽀、Hotfix分⽀的功能测试;项⽬经理 关注Production分⽀、Release分⽀。

另外要说明,项⽬阶段在时间纬度有可能重叠.⽐如:release阶段(当前版本)与下各版本的开发阶段可同时存在,因为当前release阶段的发起同时也就意味着下⼀个release的开发阶段的开始;⼀旦线上出现bug(任何时候都可能出现),紧急修复阶段就可能与开发阶段、发版阶段重叠...因此,要求团队成员都要理解Git-Flow⼯作流,以及⾃身所处的项⽬阶段.

6.2 命令行演示⼀个完整的Git-Flow流程

原理总是枯燥的,接下来实践⼀个从功能开发到版本发布的完整的流程,感受⼀下Git-Flow的具体操作.

特此说明,以下shell命令是在win10环境下,‘/e/PycharmProjects/DatawhaleChina’目录,使用git bash工具进行演示;‘$’ 符号所在行为演示命令,如有内容输出,会在‘$’ 符号所在行的下面输出。

6.2.1 初始化项⽬,创建Develop分⽀

Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina
$ pwd
/e/PycharmProjects/DatawhaleChina Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina
$ mkdir git-demo-workflow-project Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina
$ cd git-demo-workflow-project/ Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project
$ touch readme.md Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project
$ git init
Initialized empty Git repository in E:/PycharmProjects/DatawhaleChina/git-demo-workflow-project/.git/ Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git add . Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git commit -m "init"
[master (root-commit) 1ae2455] init
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme.md Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git checkout -b develop master
Switched to a new branch 'develop'
 

6.2.2 模拟开发阶段过程

(创建新功能Feature分⽀、实现⼀个⽤户登录模块、然后合并到Develop分⽀、删除功能分⽀)

Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git checkout -b feature-login develop
Switched to a new branch 'feature-login' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ touch LoginUser.html Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$echo "hi, this is user html" > LoginUser.html Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ cat LoginUser.html
hi, this is user html Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ ls
LoginUser.html readme.md Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ git add .
warning: LF will be replaced by CRLF in LoginUser.html.
The file will have its original line endings in your working directory Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ git commit -m "feat: add LoginUser.html"
[feature-login 182444e] feat: add LoginUser.html
1 file changed, 1 insertion(+)
create mode 100644 LoginUser.html Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ touch LoginUser.js Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ echo "hi, this is user js" > LoginUser.js Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ git add .
warning: LF will be replaced by CRLF in LoginUser.js.
The file will have its original line endings in your working directory Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ git commit -m "feat: add LoginUser.js"
[feature-login b0d494c] feat: add LoginUser.js
1 file changed, 1 insertion(+)
create mode 100644 LoginUser.js Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ git status
On branch feature-login
nothing to commit, working tree clean Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (feature-login)
$ git checkout develop
Switched to branch 'develop' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git merge --no-ff feature-login
Merge made by the 'recursive' strategy.
LoginUser.html | 1 +
LoginUser.js | 1 +
2 files changed, 2 insertions(+)
create mode 100644 LoginUser.html
create mode 100644 LoginUser.js Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git branch -d feature-login
Deleted branch feature-login (was b0d494c).
 

6.2.3 模拟Release阶段过程

(创建Release分⽀、进⾏bug修复、合并到Production分⽀与Develop分⽀)

Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git checkout -b release-v0.1 develop
Switched to a new branch 'release-v0.1' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (release-v0.1)
$ echo "bugifx LoginUser.html" >> LoginUser.html Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (release-v0.1)
$ git add .
warning: LF will be replaced by CRLF in LoginUser.html.
The file will have its original line endings in your working directory Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (release-v0.1)
$ git commit -m "fix: bugfix for LoginUser.html"
[release-v0.1 a37a88c] fix: bugfix for LoginUser.html
1 file changed, 1 insertion(+) Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (release-v0.1)
$ git checkout master
Switched to branch 'master' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git merge --no-ff release-v0.1
Merge made by the 'recursive' strategy.
LoginUser.html | 2 ++
LoginUser.js | 1 +
2 files changed, 3 insertions(+)
create mode 100644 LoginUser.html
create mode 100644 LoginUser.js Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git tag v0.1 Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git checkout develop
Switched to branch 'develop' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git merge --no-ff release-v0.1
Merge made by the 'recursive' strategy.
LoginUser.html | 1 +
1 file changed, 1 insertion(+) Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git branch -d release-v0.1
Deleted branch release-v0.1 (was a37a88c).
 

6.2.4 模拟线上故障,创建Hotfix分⽀

(创建Hotfix分⽀、进⾏bug修复、合并到Production分⽀与Develop分⽀)

Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git checkout -b hotfix-v0.1.1 master
Switched to a new branch 'hotfix-v0.1.1' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (hotfix-v0.1.1)
$ git status
On branch hotfix-v0.1.1
nothing to commit, working tree clean Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (hotfix-v0.1.1)
$ echo "hotfix for LoginUser.html" >> LoginUser.html Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (hotfix-v0.1.1)
$ cat LoginUser.html
hi, this is user html
bugifx LoginUser.html
hotfix for LoginUser.html Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (hotfix-v0.1.1)
$ git add .
warning: LF will be replaced by CRLF in LoginUser.html.
The file will have its original line endings in your working directory Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (hotfix-v0.1.1)
$ git commit -m "hotfix: do something for LoginUser.html"
[hotfix-v0.1.1 bcb680e] hotfix: do something for LoginUser.html
1 file changed, 1 insertion(+) Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (hotfix-v0.1.1)
$ git checkout master
Switched to branch 'master' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git merge --no-ff hotfix-v0.1.1
Merge made by the 'recursive' strategy.
LoginUser.html | 1 +
1 file changed, 1 insertion(+) Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git tag v0.1.1 Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (master)
$ git checkout develop
Switched to branch 'develop' Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git merge --no-ff hotfix-v0.1.1
Merge made by the 'recursive' strategy.
LoginUser.html | 1 +
1 file changed, 1 insertion(+) Administrator@WIN MINGW64 /e/PycharmProjects/DatawhaleChina/git-demo-workflow-project (develop)
$ git branch -d hotfix-v0.1.1
Deleted branch hotfix-v0.1.1 (was bcb680e).

文章到此结束,我们下次再见
在七十亿人海中,请把我认出来

Lecture6的更多相关文章

  1. Linear Algebra lecture6 note

    Vector spaces and subspaces Column space of A solving Ax=b Null space of A   Vector space requiremen ...

  2. cs231n spring 2017 lecture6 Training Neural Networks I 听课笔记

    1. 激活函数: 1)Sigmoid,σ(x)=1/(1+e-x).把输出压缩在(0,1)之间.几个问题:(a)x比较大或者比较小(比如10,-10),sigmoid的曲线很平缓,导数为0,在用链式法 ...

  3. Lecture6.概率极限理论

    一.随机变量序列的收敛性 1.定义 (1)概率为1收敛: 如果$P{\lim\limits_{n \to \infty}X_n = X} = 1$,则称{Xn}概率为1地收敛于X,或几乎处处(几乎必然 ...

  4. cs231n spring 2017 lecture6 Training Neural Networks I

    1. 激活函数: 1)Sigmoid,σ(x)=1/(1+e-x).把输出压缩在(0,1)之间.几个问题:(a)x比较大或者比较小(比如10,-10),sigmoid的曲线很平缓,导数为0,在用链式法 ...

  5. cs231n学习笔记——lecture6 Training Neural Networks

    该博客主要用于个人学习记录,部分内容参考自:[基础]斯坦福cs231n课程视频笔记(三) 训练神经网络.[cs231n笔记]10.神经网络训练技巧(上).CS231n学习笔记-训练神经网络.整理学习之 ...

  6. lecture3-线性神经元和算法

    Hinton第三课 这节课主要是介绍NN的输出端常用的神经元,然后重点是说明怎么使用BP来计算偏导数,在Hinton这一课中,他提供了他1986年参与写的<并行分布处理>一书的第8章,49 ...

  7. GO語言視頻教程

    第1课:https://github.com/Unknwon/go-fundamental-programming/blob/master/lectures/lecture1.md Go开发环境搭建h ...

  8. 机器学习 —— 基础整理(五)线性回归;二项Logistic回归;Softmax回归及其梯度推导;广义线性模型

    本文简单整理了以下内容: (一)线性回归 (二)二分类:二项Logistic回归 (三)多分类:Softmax回归 (四)广义线性模型 闲话:二项Logistic回归是我去年入门机器学习时学的第一个模 ...

  9. SLAM(二)----学习资料下载

    有位师兄收集了很多slam的学习资料, 做的很赞, 放到了github上, 地址:https://github.com/liulinbo/slam.git ruben update 0823 2016 ...

  10. [Hinton] Neural Networks for Machine Learning - Basic

    Link: Neural Networks for Machine Learning - 多伦多大学 Link: Hinton的CSC321课程笔记1 Link: Hinton的CSC321课程笔记2 ...

随机推荐

  1. 阿里云张振尧:阿里云边缘云驱动5G时代行业新价值

    ​简介:近日,以"5G融合通信趋势下的技术创新"为主题的2021中国增值电信及虚拟运营高峰论坛在北京召开,阿里云边缘云高级产品专家张振尧发表了<阿里云边缘云驱动5G时代行业新 ...

  2. [Trading] 股票日内交易者能赚多少钱 - 看到日内交易的潜力并学习如何实现它

    无论是为了生活方式.寻求刺激还是为了挑战,股票市场短线交易者能赚多少钱的问题不可避免地出现了. 股票日内交易者的交易量变化很大,一些当日交易者损失了他们的资金,而另一些人利用他们的资金创造了一个高的月 ...

  3. dotnet 6 推荐一个可代替 .NET Remoting 的 IPC 库

    本文将来和大家推荐一个基于最友好 MIT 协议的完全在 GitHub 上开源的,可代替 .NET Remoting 的 IPC 本机多进程通讯库 本机内多进程通讯 IPC 不同于跨设备系统的 RPC ...

  4. dotnet OpenXML 读取 PPT 形状边框定义在 Style 的颜色画刷

    本文来和大家聊聊在 PPT 形状使用了 Style 样式的颜色画刷读取方法 在开始之前,期望大家已了解如何在 dotnet 应用里面读取 PPT 文件,如果还不了解读取方法,请参阅 C# dotnet ...

  5. WPF 加载诡异的字体无法布局

    如果在系统里面存在诡异的字体,同时自己的 WPF 中有一个控件尝试使用这个字体放在界面中,那么将会在界面布局过程炸了,整个控件或者整个界面布局都无法继续 本文本来是由吕水大大发布的,但是他没空写,于是 ...

  6. Jenkins+Harbor+gogs+docker+portainer+springboot实现devOps(企业实战)

    本篇主要讲述springboot以及vue前后端分离项目,使用Jenkins拉取gogs代码仓库源码,构建Docker镜像并推送至Harbor仓库,使用docker 可视化部署工具[portainer ...

  7. 局域网内一部分网络设备无法ping通,icmp_seq=1 目标主机不可达

    问题: 来自 192.168.2.99 icmp_seq=1 目标主机不可达.   最近想在局域网内搭建一台服务器,打开SSH服务后发现局域网内的一部分设备无法使用,尝试了各种办法都没能解决,重装系统 ...

  8. 构建RAG应用-day05: 如何评估 LLM 应用 评估并优化生成部分 评估并优化检索部分

    评估 LLM 应用 1.一般评估思路 首先,你会在一到三个样本的小样本中调整 Prompt ,尝试使其在这些样本上起效. 随后,当你对系统进行进一步测试时,可能会遇到一些棘手的例子,这些例子无法通过 ...

  9. 从SAP CRM上传设备到SAP ERP

    文档<Step by step to download equipment from ERP with hierarchy>描述了从ERP复制设备到CRM的步骤.默认情况下,ERP中的设备 ...

  10. 如果win报错无法加载文件 C:\Users\xx\AppData\Roaming\npm\pnpm.ps1,因为在此系统上禁止运行脚本

    点击查看代码 Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass