Gitflow概念
Gitflow工作流程中永远存在两个分支:master和develop。
- master分子是生产分支,一旦改变即意味着有新的版本;
- develop分支是日常开发分支,永远保持最新代码,当该分支的代码稳定到可以发布的时候,要merge到master分支,并tag上版本号。
- feature分支,从develop分支来,最终到develop分支去。主要为将来的一个【未知的新版本】开发新特性,只要这个feature还在开发,这个分支就存在,最终被merge到develop分支,成为新版本的一个新feature,或者被弃用。
- release分支,从develop分支来,最终要合并到develop和master分支。主要是为新版本发布做准备,如小bug的修复和为发布准备元数据。这样develop分支上,还能继续接受下一个大版本的feature。
- hotfix是发生在release finish之后的。比如你发布了v1.2.1,也就是说merge到了master分支。然后发现有bug,就在master分支上,开hotfix分支,hotfix/v1.2.2,fix bug之后,发布hotfix,也就是说把hotfix/v1.2.2 merge到master分支
Git和Git-flow之间的关系
Initialize
// gitflow
git flow init
// git
git init
git commit --allow-empty -m "Initial commit"
git checkout -b develop master
Create a feature branch
// gitflow
git flow feature start myFeature
//git
git checkout -b feature/git flow feature pull origin develop
Get latest for a feature branch
// gitflow
git flow feature pull origin myFeature
// git
git checkout feature/myFeature
git pull --rebase origin feature/myFeature
Finalize a feature branch
// gitflow
git flow feature finish myFeature
// git
git checkout develop
git merge --no-ff feature/myFeature
git branch -d feature/myFeatureCreate a release branch
Push the merged feature branch
git push origin develop
git push origin delete:feature/myFeature
Create a release branch
// gitflow
git flow release start 1.2.0
// git
git checkout -b release/1.2.0 develop
Share a release branch
// gitflow
git flow release publish 1.2.0
// git
git checkout release/1.2.0
git push origin release/1.2.0
Get latest for a release branch
git checkout release/1.2.0
git pull --rebase origin release/1.2.0
Finalize a release branch
// gitflow
git flow release finish 1.2.0
// git
git checkout master
git merge --no-ff release/1.2.0
git tag -a 1.2.0
git checkout develop
git merge --no-ff release/1.2.0
git branch -d release/1.2.0
Push the merged feature branch
git push origin master
git push origin develop
git push origin --tags
git push origin :release/1.2.0
Create a hotfix branch
// gitflow
git flow hotfix start 1.2.1 [commit]
// git
git checkout -b hotfix/1.2.1 [commit]
Finalize a hotfix branch
// gitflow
git flow hotfix finish 1.2.1
// git
git checkout master
git merge --no-ff hotfix/1.2.1
git tag -a 1.2.1
git checkout develop
git merge --no-ff hotfix/1.2.1
git branch -d hotfix/1.2.1
Push the merged hotfix branch
git push origin master
git push origin develop
git push origin --tags
git push origin :hotfix/1.2.1