一、主分支Master
首先,代码库应该有一个、且仅有一个主分支。所有提供给用户使用的正式版本,都在这个主分支上发布。
First, the code base should have only one main branch. All official versions available to the user are posted on this main branch.
Git主分支的名字,默认叫做Master。它是自动建立的,版本库初始化以后,默认就是在主分支在进行开发。
The name of the main branch of Git, which is called Master by default. It is created automatically. After initializing the repository, the default settings are developed in the main branch.
目前我们dlp项目没有使用tag的方式,都是每次发布版本的时候打一个分支。这样的缺点就是没有一条主线可以追溯历史版本。
At present, our dlp project does not use tags. It is a branch every time the version is released. The downside is that no main line can be traced back to the historical version.
虽然说分支有版本名称。但是没有tag在master一条主线上的来的清晰。其实tag的功能跟分支类似。
Although the branch has a version name. But no tag is clear on the main line of the master. In fact, the function of the tag is similar to the branch.
而且每个tag都可以打上详细的说明以及注释。打上标签的同时,写上附带信息,可以更方便项目日后维护过程中的回溯和复查。
And each tag can be accompanied by detailed instructions and comments. At the same time as labeling,writing the accompanying information can make it easier to backtrack and review the project in the future maintenance process.
二、开发分支Develop
主分支只用来发布重大版本,日常开发应该在另一条分支上完成。我们把开发用的分支,叫做Develop。
The main branch is only used to distribute major versions, and daily development should be done on another branch.We use the branch for development, called Develop.
这个分支可以用来生成代码的最新隔夜版本(nightly)。如果想正式对外发布,就在Master分支上,对Develop分支进行"合并"(merge)。
This branch can be used to generate the latest nightly version of the code (per night).
If you want to officially release it, you will "merge" the Develop branch on the Master branch.
#Git创建Develop分支的命令:
Git creates the command for the Develop branch:
git checkout -b develop master
将Develop分支发布到Master分支的命令:
The command to publish the Develop branch to the Master branch:
#切换到Master分支
git checkout master
#对Develop分支进行合并
git merge --no-ff develop
这里稍微解释一下,上一条命令的--no-ff参数是什么意思。默认情况下,Git执行"快进式合并"(fast-farward merge),会直接将Master分支指向Develop分支。
Here is a brief description of the meaning of the --no-ff parameter of the previous command. By default, Git performs a "quick merge" to direct the Master branch to the Develop branch.
使用--no-ff参数后,会执行正常合并,在Master分支上生成一个新节点。为了保证版本演进的清晰,我们希望采用这种做法。
关于合并的更多解释,请参考Benjamin Sandofsky的《Understanding the Git Workflow》。
After the --no-ff parameter is used, a normal merge is performed and a new node is generated on the Master branch. In order to ensure the clarity of the version evolution,
we hope to adopt this approach. For more explanation on the merger, please refer to Benjamin Sandofsky
三、临时性分支 (Temporary branch
)
前面讲到版本库的两条主要分支:Master和Develop。前者用于正式发布,后者用于日常开发。其实,常设分支只需要这两条就够了,不需要其他了。
I talked about the two main branches of the repository: Master and Develop. The former is used for official release and the latter for daily development. In fact, the permanent branch only needs these two articles, and no other is needed.
但是,除了常设分支以外,还有一些临时性分支,用于应对一些特定目的的版本开发。临时性分支主要有三种:
However, in addition to the standing branch, there are temporary branches for version development for specific purposes.
临时分支主要有三种类型:(
There are three main types of temporary branches:
)
- 功能(feature)分支
- 预发布(release)分支
- 修补bug(fixbug)分支
这三种分支都属于临时性需要,使用完以后,应该删除,使得代码库的常设分支始终只有Master和Develop。
These three branches are temporary requirements. After use, they should be deleted,
so that the permanent branch of the code base always has only Master and Develop.
四、 功能分支(Functional branch
)
接下来,一个个来看这三种"临时性分支"。
Next, look at the three "temporary branches" one by one.
第一种是功能分支,它是为了开发某种特定功能,从Develop分支上面分出来的。开发完成后,要再并入Develop。
The first is a feature branch that extracts specific functions from the Develop branch. Once the development is complete, it will be merged into Develop.
功能分支的名字,可以采用feature-*
的形式命名。
The name of the function branch can be named in the form of feature-* .
#创建一个功能分支:
Create a function branch:
git checkout -b feature-x develop
#开发完成后,将功能分支合并到develop分支:
After the development is complete, merge the feature branches into the develop branch:
git checkout develop
git merge --no-ff feature-x
#删除feature分支:Delete the feature branch:
git branch -d feature-x
五、预发布分支(目前我们可以不需要)
Pre-release branch (currently we don't need it)
第二种是预发布分支,它是指发布正式版本之前(即合并到Master分支之前),我们可能需要有一个预发布的版本进行测试。
The second is the pre-release branch, which refers to the release of the official version (ie before the merge to the Master branch), we may need to have a pre-release version for testing.
目前dlp项目在预发布之前其实master相当于一个预发布的版本。此分支可以要也可以不要。
Currently the dlp project is actually a pre-release version before the pre-release. This branch may or may not be required.
预发布分支是从Develop分支上面分出来的,预发布结束以后,必须合并进Develop和Master分支。它的命名,可以采用release-*的形式。
The pre-release branch is split from the Develop branch. After the pre-release is complete,
it must be merged into the Develop and Master branches. Its naming can be in the form of release-*.
#创建一个预发布分支:
git checkout -b release-1.2 develop
#确认没有问题后,合并到master分支:
git checkout master
git merge --no-ff release-1.2
# 对合并生成的新节点,做一个标签
git tag -a 1.2
#再合并到develop分支:
git checkout develop
git merge --no-ff release-1.2
#最后,删除预发布分支:
git branch -d release-1.2
六、修补bug分支(Patch bug branch)
最后一种是修补bug分支。软件正式发布以后,难免会出现bug。这时就需要创建一个分支,进行bug修补。
The last one is to patch the bug branch. After the software is officially released, it will inevitably lead to bugs. At this point you need to create a branch for bug fixes.
修补bug分支是从Master分支上面分出来的。修补结束以后,再合并进Master和Develop分支。它的命名,可以采用fixbug-*的形式。
The patching bug branch is split from the master branch. After the patch is complete, merge into the Master and Develop branches. Its naming can be in the form of fixbug-*.
#创建一个修补bug分支:
git checkout -b fixbug-0.1 master
#修补结束后,合并到master分支:
git checkout master
git merge --no-ff fixbug-0.1
git tag -a 0.1.1
#再合并到develop分支:
git checkout develop
git merge --no-ff fixbug-0.1
#最后,删除"修补bug分支":
git branch -d fixbug-0.1