git-flow 原理:A successful Git branching model,两篇不错的中文翻译: Git开发管理之道一个成功的Git分支模型

简单来说,git-flow 就是在 git branch git tag基础上封装出来的代码分支管理模型,把实际开发模拟成 master develop feature release hotfix support 几种场景,其中 master 对应发布上线,develop 对应开发,其他几个在不同的情况下出现。通过封装,git-flow 屏蔽了 git branch 等相对来说比较复杂生硬的命令(git branch 还是比较复杂的,尤其是在多分支情况下),简单而且规范的解决了代码分支管理问题。

安装 git-flow:

1
brew install git-flow

在一个全新目录下构建 git-flow 模型:

1
2
3
4
5
6
7
8
9
10
11
12
➜ git flow init
Initialized empty Git repository in /Users/fannheyward/flowTest/.git/
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []

或者在现有的版本库构建:

1
2
3
4
5
6
7
8
9
10
11
12
➜ git flow init
Which branch should be used for bringing forth production releases?
- master
Branch name for production releases: [master]
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []

中间会询问生成的分支名,直接回车默认。这样一个 git-flow 分支模型就初始化完成。

使用场景一:新功能开发,代号 f1

1
2
3
4
5
6
7
8
9
10
➜ git flow feature start f1
Switched to a new branch 'feature/f1'
Summary of actions:
- A new branch 'feature/f1' was created, based on 'develop'
- You are now on branch 'feature/f1'
Now, start committing on your feature. When done, use:
git flow feature finish f1

git-flow 从 develop 分支创建了一个新的分支 feature/f1,并自动切换到这个分支下面。然后就可以进行 f1 功能开发,中间可以多次的 commit 操作。当功能完成后:

1
2
3
4
5
6
7
8
9
➜ git flow feature finish f1
Switched to branch 'develop'
Already up-to-date.
Deleted branch feature/f1 (was 7bb5749).
Summary of actions:
- The feature branch 'feature/f1' was merged into 'develop'
- Feature branch 'feature/f1' has been removed
- You are now on branch 'develop'

feature/f1 分支的代码会被合并到 develop 里面,然后删除该分支,切换回 develop. 到此,新功能开发这个场景完毕。在 f1 功能开发中,如果 f1 未完成,同时功能 f2 要开始进行,也是可以的。


使用场景二:发布上线,代号 0.1

1
2
3
4
5
6
7
8
9
10
11
12
13
➜ git flow release start 0.1
Switched to a new branch 'release/0.1'
Summary of actions:
- A new branch 'release/0.1' was created, based on 'develop'
- You are now on branch 'release/0.1'
Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:
git flow release finish '0.1'

git-flow 从 develop 分支创建一个新的分支 release/0.1,并切换到该分支下,接下来要做的就是修改版本号等发布操作。完成后:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
➜ git flow release finish 0.1
Switched to branch 'master'
Merge made by the 'recursive' strategy.
f1 | 1 +
version | 1 +
2 files changed, 2 insertions(+)
create mode 100644 f1
create mode 100644 version
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
version | 1 +
1 file changed, 1 insertion(+)
create mode 100644 version
Deleted branch release/0.1 (was d77df80).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged '0.1'
- Release branch has been back-merged into 'develop'
- Release branch 'release/0.1' has been deleted

git-flow 会依次切换到 master develop 下合并 release/0.1 里的修改,然后用 git tag 的给当次发布打上 tag 0.1,可以通过 git tag 查看所有 tag:

1
2
3
➜ git:(master) git tag
0.1
0.2

使用场景三:紧急 bug 修正,代号 bug1

1
2
3
4
5
6
7
8
9
10
11
12
13
➜ git flow hotfix start bug1
Switched to a new branch 'hotfix/bug1'
Summary of actions:
- A new branch 'hotfix/bug1' was created, based on 'master'
- You are now on branch 'hotfix/bug1'
Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:
git flow hotfix finish 'bug1'

git-flow 从 master 分支创建一个新的分支 hotfix/bug1,并切换到该分支下。接下来要做的就是修复 bug,完成后:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
➜ git flow hotfix finish bug1
Switched to branch 'master'
Merge made by the 'recursive' strategy.
f1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
f1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Deleted branch hotfix/bug1 (was aa3ca2e).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch has been merged into 'master'
- The hotfix was tagged 'bug1'
- Hotfix branch has been back-merged into 'develop'
- Hotfix branch 'hotfix/bug1' has been deleted

git-flow 会依次切换到 master develop 分支下合并 hotfix/bug1,然后删掉 hotfix/bug1。到此,hotfix 完成。

git-flow 的 feature release 都是从 develop 分支创建,hotfix support 都是从 master 分支创建。

来源:http://fann.im/blog/2012/03/12/git-flow-notes/

Git-flow 使用笔记的更多相关文章

  1. Bear 實驗室: 什麼是Git flow ? 如何在SourceTree使用Git flow管理開發!

      http://www.takobear.tw/12/post/2014/02/bear-git-flow-sourcetreegit-flow.html     Bear 實驗室: 什麼是Git ...

  2. Git 在团队中的最佳实践--如何正确使用Git Flow

    我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确使用. Git的优点 Git的优点很多,但是这里只列出我认为 ...

  3. Git 在团队中的最佳实践--如何正确使用Git Flow[转]

    原文地址:http://www.cnblogs.com/cnblogsfans/p/5075073.html Git的优点 Git的优点很多,但是这里只列出我认为非常突出的几点. 由于是分布式,所有本 ...

  4. GIT FLOW 时序图

    git flow sequence md link: git branching model master->master branch: use default branch Note rig ...

  5. 基于git的源代码管理模型——git flow

    基于git的源代码管理模型--git flow A successful Git branching model

  6. git flow的使用

    简介 Gitflow工作流程围绕项目发布定义了严格的分支模型.尽管它比Feature Branch Workflow更复杂一些,但它也为管理更大规模的项目提供了坚实的框架. 与Feature Bran ...

  7. 引入git flow分支管理

    git flow是Vincent Driessen提出了一个分支管理的策略,非常值得借鉴.它可以使得版本库的演进保持简洁,主干清晰,各个分支各司其职.井井有条. 先看下Vincent Driessen ...

  8. git flow的安装和使用

    确保安装了git 1.windows系统下安装 进入cmd clone github上的gitflow到一个文件夹下 我这里clone到 c:\gitflow git clone git://gith ...

  9. git以及git flow 的使用

    转载:http://selfcontroller.iteye.com/blog/996494 在这里主要讲一下我在项目中用到的关于gitflow的用法.   公司的项目中,专门有一台用来存放版本库的服 ...

  10. 基于SourceTree 下的 Git Flow 模型

    基于SourceTree 下的 Git Flow 模型 1. sourceTree  是一个开源的git 图形管理工具,可下载mac版本,windows版本 2. Git Flow 是一套使用Git进 ...

随机推荐

  1. Simulink仿真入门到精通(十七) Simulink代码生成技术详解

    17.1 基于模型的设计 基于模型设计是一种流程,较之传统软件开发流程而言,使开发者能够更快捷.更高效地进行开发.适用范围包括汽车电子信号处理.控制系统.通信行业和半导体行业. V字模型开发流程整体描 ...

  2. Python模块二

    os模块是与操作系统交互的一个接口​ <em>#和文件夹相关 os.makedirs('dirname1/dirname2')    可生成多层递归目录 os.removedirs('di ...

  3. oracle中plsql练习-----在控制台输出1到100以内的素数。

    一.思路:首先需要知道素数的概念即质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数. 中心思想是,外循环所有的自然数,内循环折半查询,增加代码的速度,注意:从1开始,需要大于1,但是pl ...

  4. ECharts的使用与总结

    ECharts的使用与总结 一,介绍与需求 1.1,介绍 ECharts商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9 ...

  5. [深入学习C#] 匿名函数、委托和Lambda表达式

    匿名函数 匿名函数(Anonymous Function)是表示“内联”方法定义的表达式.匿名函数本身及其内部没有值或者类型,但是可以转换为兼容的委托或者表达式树类型(了解详情).匿名函数转换的计算取 ...

  6. Django之路由层和视图层详解

    路由层 首先我们来看一下,路由层都有哪些东西,其实你看django很人性化,将所有的介绍都放在了简介里面,不信,你看

  7. hdu3665Floyd解法

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/3665/ Floyd是经典的dp算法,将迭代过程分成n个阶段,经过n个阶段的迭代所有点对之间的最短路径都可以求出, ...

  8. body体里面传///貌似jmeter不支持

    原因是:当接口请求参数含\\\时请求到服务器端是\\,少了一个\导致参数不合法报错:求助一个大神说是 因为如标题 : 解决如上图所示,完美解决

  9. Prism 源码解读1-Bootstrapper和Region的创建

    介绍 之前也研究过Prism框架但是一直没有深入理解,现在项目上想把一个Winform的桌面应用程序改造成WPF程序,同时我希望程序是可测试可维护架构良好的,Prism的这些设计理念正好符合我的需求, ...

  10. 进制-Iterative-进制转换

    2019-12-02 21:15:31 进制转换是计算机科学里的一个基础算法,通常可以使用如下的模版来进行计算. 下面我们来讨论一些关于进制的题目. 1271. Hexspeak  问题描述: 问题求 ...