工作流记录
master分支和develop分支
基础
The main branch stores the official release history, and the develop branch serves as an integration branch for features. It's also convenient to tag all commits in the main branch with a version number.
主分支用于正式发布版本,使用版本号进行记录,develop分支用于新功能的集成。
This branch will contain the complete history of the project, whereas main will contain an abridged version. Other developers should now clone the central repository and create a tracking branch for develop.
develop分支将包含项目的完整历史记录,其他开发人员修改bug或新增新功能时,应该从develop创建一个跟踪分支,完成后合并到develop分支上,当功能都开发完成时,合并到master分支上进行发布新版本。
release分支
Once develop has acquired enough features for a release (or a predetermined release date is approaching), you fork a release branch off of develop. Creating this branch starts the next release cycle, so no new features can be added after this point—only bug fixes, documentation generation, and other release-oriented tasks should go in this branch. Once it's ready to ship, the release branch gets merged into main and tagged with a version number. In addition, it should be merged back into develop, which may have progressed since the release was initiated.
一旦 develop 准备好了所有的新功能(或者预定的发布日期临近),就可以从 develop 分支迁出release分支。 (此时功能大致已经完成,创建relese用于修复剩余Bug)
创建release分支会启动下一个发布周期,因此在此之后不能添加新功能——只有错误修复、文档生成和其他面向发布的任务应该在此分支中进行。
准备好发布后,release分支会合并到master分支中并带有版本号标记。 此外,它应该重新合并到开发中,这可能自发布开始以来已经取得了进展。
Once the release is ready to ship, it will get merged it into main and develop, then the release branch will be deleted. It’s important to merge back into develop because critical updates may have been added to the release branch and they need to be accessible to new features. If your organization stresses code review, this would be an ideal place for a pull request.
release分支完成后,合并到master分支,之后release分支会被删除,最后合并到develop分支也是很重要的。
Hotfix分支
Maintenance or “hotfix” branches are used to quickly patch production releases. Hotfix branches are a lot like release branches and feature branches except they're based on main instead of develop. This is the only branch that should fork directly off of main. As soon as the fix is complete, it should be merged into both main and develop (or the current release branch), and main should be tagged with an updated version number.
Having a dedicated line of development for bug fixes lets your team address issues without interrupting the rest of the workflow or waiting for the next release cycle. You can think of maintenance branches as ad hoc release branches that work directly with main. A hotfix branch can be created using the following methods:
修复版本用于快速修补发布版本。一般是紧急修复。此分支是基于master分支,这是唯一一个可以直接合并到master分支的一种分支。修复完成后,应将其合并到master分支和develop分支(或当前release分支)中,并且master分支应使用更新的版本号进行标记。
例子
release 和 feature分支
git checkout main
git checkout -b develop
git checkout -b feature_branch
# work happens on feature branch
git checkout develop
git merge feature_branch
git checkout main
git merge develop
git branch -d feature_branch
hotfix分支
git checkout main
git checkout -b hotfix_branch
# work is done commits are added to the hotfix_branch
git checkout develop
git merge hotfix_branch
git checkout main
git merge hotfix_branch
总结
A develop branch is created from main
A release branch is created from develop
Feature branches are created from develop
When a feature is complete it is merged into the develop branch
When the release branch is done it is merged into develop and main
If an issue in main is detected a hotfix branch is created from main
Once the hotfix is complete it is merged to both develop and main