首页 iOS.& Swift Books 高级git

10
Gitflow Workflow. 由Jawwad Ahmad撰写

Gitflow是一个工作流程,Vincent Driesen在他的2010年博客文章中介绍, 一个成功的git分支模型.

在其核心,Gitflow是分支工作流的专门版本。它引入了一些不同类型的分支,具有明确定义的规则,即如何在它们之间流动。

Vincent在原始博客文章的开始时发布了一个十月5月5日的“反思注意事项”的十年更新。在他的注意事项中,他建议您考虑这是否是您的正确工作流程。

他指出,Gitflow非常适合版本化软件,但在当今的连续部署时,更简单的方法可能会更好地工作。他用文字结束了他的纸条:“为自己决定”。

在本章中,您将了解构成Gitflow的规则以及它们背后的原因。这将允许您确定Gitflow是否适合您。

何时使用gitflow

如果您构建明确版本化的软件,Gitflow是一个很好的契合,特别是如果您需要同时支持多个版本的软件。例如,您可能会发布一个2.0版本的桌面应用程序,这是付费升级,但仍然希望继续为1.0版本释放次要错误修复更新。

如果您的项目有常规发布周期,Gitflow也很好。它的释放分支工作流程允许您测试和稳定您的发布,而正常的日常开发继续在主要开发分支中继续。

Gitflow Scece管理更大的项目更加明确地定义了代码移动的移动。

Gitflow在有利于连续部署模型的方案中不太理想,例如Web开发。在这些情况下,Gitflow的释放工作流可能会增加不必要的额外开销。

章节图

在本章中,您将首先快速地介绍Gitflow中的基本概念。您将了解不同的长寿和短期的分支机构以及如何创建和合并它们的规则。

Gitflow分支的类型

Gitflow使用两个长寿分支: 掌握发展 和三个主要 类型 短暂的分支机构: 特征, 释放修补程序。虽然7从未删除了长达的分支机构,但您将删除短LEDTED分支的分支,以便合并在一个长期的分支中支付。

长寿分支

GI.t本身使用单个长寿分支,这是 掌握 分支。 Gitflow介绍了额外的长寿的概念 生产 branch.

枝条

三种主要类型的短寿命 特征, 释放修补程序.

创建和合并分支机构的规则

以下是创建和合并分支机构的规则:

Gitflow的分支和合并流为特征,释放和修补程序分支机构
Zoxkdel'J JXijdhihm Tokyizk Tokyizk GAF GAF,XAREIKI OTT MOHCEJ MXOYKVIH

用于修补程序的替代流程并释放后部合并硕士
og udnoczuni zcuv jan jawxir eqw giluevi bhuz yibq is disspid ikza muxugok

安装git-flow

The git-flow extensions are a library of Git subcommands that make it easier to adopt the Gitflow workflow. For example, a single GI.t flow release finish command will merge your release branch into master, tag the release, merge it back into develop and then finally delete the release branch.

brew install git-flow-avh
GI.t flow version

初始化Git-Flow

解压缩 repos.zip. 来自 起动机 本章文件夹。你只能在工作 亚历克斯/清单 存储库,所以 b乍得 来自先前章节的目录不包括在内。

起动机
└── repos
    ├── alex
    │   └── checklists
    └── checklists.git
cd path/to/starter/repos/alex/checklists
GI.t 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/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? [] v
Hooks and filters directory? [...]

创建和合并功能分支

Gitflow使用特征分支来完成新功能的工作,就像分支工作流一样。由于Gitflow的日常开发分支现在正在 发展 代替 掌握,您创建功能分支 发展 并合并他们回到 发展 当你完成后。您无法从中创建功能分支 掌握 或任何其他短期分支。

GI.t flow feature start update-h1-color
GI.t checkout -b feature/update-h1-color  # equivalent to above
Summary of actions:
- A new branch 'feature/update-h1-color' was created, based on 'develop'
- You are now on branch 'feature/update-h1-color'
 h1 {
-    color: navy;
+    color: blue;
 }
GI.t commit -am "Updated h1 color from navy to blue"
1. Checkout the develop branch            # git checkout develop
2. Merge the feature branch  # git merge feature/update-h1-color
3. Delete the branch     # git branch -d feature/update-h1-color
GI.t flow feature finish
Summary of actions:
- The feature branch 'feature/update-h1-color' was merged into 'develop'
- Feature branch 'feature/update-h1-color' has been locally deleted
- You are now on branch 'develop'

创建和合并释放分支

释放 分支机构是准备即将发布的代码的地方。他们让您运行测试并实施修复,而日常开发继续开发分支。

GI.t flow release start 1.0.0 --showcommands
GI.t checkout -b release/1.0.0 develop
echo '1.0.0' > VERSION
git add VERSION
git commit -m "Adding VERSION file for initial release"
# Merge release into master
git checkout master
git merge --no-ff release/1.0.0

# Tag the release
git tag -a v1.0.0

# Merge master back to develop
git checkout develop
git merge --no-ff master

# Delete the branch
git branch -d release 1.0.0
GI.t flow release finish --showcommands
Summary of actions:
- Release branch 'release/1.0.0' has been merged into 'master'
- The release was tagged 'v1.0.0'
- Release tag 'v1.0.0' has been back-merged into 'develop'
- Release branch 'release/1.0.0' has been locally deleted
- You are now on branch 'develop'
GI.t checkout master
...
git merge --no-ff release/1.0.0
...
git tag -a v1.0.0
git checkout develop
...
git merge --no-ff v1.0.0  # instead of: git merge --no-ff master
...
git branch -d release/1.0.0
GI.t -P log --oneline -1 v1.0.0
git -P log --oneline -1 master
85c2e4e (tag: v1.0.0, master) Merge branch 'release/1.0.0'

返回合并主机与合并版本

以下图像显示了返回合并时发生的步骤 掌握 进入 发展:

背部合并硕士进入
LAVV-PAPVARX CEQQIX OMQE Yuninuq

将释放分支合并到开发中
rongutc qku绳索jkiywq egne rifujum

创建和合并修补程序分支

你用 修补程序 分支机构来修复生产中的错误,因此您必须从中创建它们 掌握 branch.

GI.t flow hotfix start 1.0.1 --showcommands
GI.t checkout -b hotfix/1.0.1 master
 h1 {
-    color: blue;
+    color: midnightblue;
 }
GI.t commit -am "Updated h1 color from blue to midnightblue"
echo '1.0.1' > VERSION
GI.t commit -am "Updated VERSION to 1.0.1"
GI.t flow finish --nobackmerge --showcommands
Summary of actions:
- Hotfix branch 'hotfix/1.0.1' has been merged into 'master'
- The hotfix was tagged 'v1.0.1'
- Hotfix branch 'hotfix/1.0.1' has been merged into 'develop'
- Hotfix branch 'hotfix/1.0.1' has been locally deleted
- You are now on branch 'develop'
- Hotfix tag 'v1.0.1' has been back-merged into 'develop'
GI.t checkout master
...
git merge --no-ff hotfix/1.0.1
...
git tag -a v1.0.1
git checkout develop
...
git merge --no-ff hotfix/v1.0.1  # not: git merge --no-ff v1.0.1
...
git branch -d hotfix/1.0.1

使用git描述

The GI.t describe command shows you the most recent tag that’s accessible from a commit. If the tag is on the current commit, GI.t describe will show the tag itself. On the other hand, if the tag is on one of the ancestors, it will also show the number of additional commits and the commit hash in the following format:

{tag}-{number-of-additional-commits-from-tag}-g{commit hash}
v1.0.0-4-g827ddd8
827ddd8 (HEAD -> develop) Merge branch 'hotfix/1.0.1' into de...
b4990c4 Updated VERSION to 1.0.1
20df16b Updated h1 color from blue to midnightblue
404639f Merge tag 'v1.0.0' into develop
2249859 (tag: v1.0.0) Merge branch 'release/1.0.0'
fatal: No tags can describe 'c0623652f3f7979f664918689fca42e9...
v1.0.1

探索Git-Flow库

The GI.t-flow library includes a few additional commands that can be helpful, such as delete for deleting a type of branch or publish for pushing it to the remote.

Available subcommands are:
   init      Initialize a new git repo with support for the b...
   feature   Manage your feature branches.
   bugfix    Manage your bugfix branches.
   release   Manage your release branches.
   hotfix    Manage your hotfix branches.
   support   Manage your support branches.
   version   Shows version information.
   config    Manage your git-flow configuration.
   log       Show log deviating from base branch.

Try 'git flow <subcommand> help' for details.
$ git flow release help
usage: git flow release [list]
   or: git flow release start
   or: git flow release finish
   or: git flow release publish
   or: git flow release track
   or: git flow release delete

    Manage your release branches.

    For more specific help type the command followed by --help
$ git flow release publish --help
usage: git flow release publish [-h] <name>

    Publish the release branch <name> on origin

    -h, --help            Show this help
    --showcommands        Show git commands while executing them

关键点

  • 主分支用作生产分支。
  • 发展分支是正常的日常发展。
  • 功能分支用于新功能开发。
  • 释放分支用于文本,稳定和部署到生产释放。
  • 使用修补程序分支来修复您发布到生产的错误。
  • 您可以从开发和合并它们开发的功能分支。
  • 您创建发行分支从开发并合并它们以掌握和开发。
  • 您可以从Master创建修补程序分支并合并它们以掌握和开发。
  • Install the newer AVH version of git-flow with brew install git-flow-avh.

有一个技术问题?想报告一个错误吗? 您可以向官方书籍论坛中的书籍作者提出问题和报告错误 这里.

有反馈分享在线阅读体验吗? 如果您有关于UI,UX,突出显示或我们在线阅读器的其他功能的反馈,您可以将其发送到设计团队,其中表格如下所示:

© 2021 Razeware LLC

您可以免费读取,本章的部分显示为 混淆了 文本。解锁这本书,以及我们整个书籍和视频目录,带有Raywenderlich.com的专业订阅。

现在解锁

要突出或记笔记,您需要在订阅中拥有这本书或自行购买。