Git是一种非常强大的DVCS, 它的分支功能非常出色,有爱好者根据实际经验设计出一套基于分支的开发/发布模型, 原文见:http://nvie.com/posts/a-successful-git-branching-model/, 这个模型的概念如下图:
根据这个模型,Hacker们又开发出了一套基于这种模型的Git子模块, 名叫Git FLow. 它提供了一系列扩展命令,可以使开发者在自己的项目中方便的使用上文提到的开发模型.
安装
源码安装
$ git clone --recursive git:
//github.com/nvie/gitflow.git
$ cd gitflow
$ [sudo] make install
|
安装补全模块
为了便于记忆与使用
$ git clone http:
//github.com/bobthecow/git-flow-completion
$ cd git-flow-completion ; ls
git-flow-completion.bash
git-flow-completion.zsh
LICENSE
README.markdown
|
zsh : ~/.zshrc
在配置文件(~/.zshrc)中引入补全函数
... source /path/to/git-flow-completion.zsh
使用方法
STEP1: 初始化gitflow仓库
$ git clone git@192.168.48.12:xxx.git $ cd xxx # 下载xxx旧版的develop分支到本地 master> git checkout -b develop origin/develop Branch develop set up to track remote branch develop from origin. Switched to a new branch 'develop' # 初始化git flow 仓库, 一路默认即可 develop> git flow init /tmp/x/xxx Which branch should be used for bringing forth production releases? - develop - master Branch name for production releases: [master] Which branch should be used for integration of the "next release"? - develop 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? []
STEP2: 建立开发新功能的分支
$ git flow feature start SmsWidget Switched to a new branch 'feature/SmsWidget' Summary of actions: - A new branch 'feature/SmsWidget' was created, based on 'develop' - You are now on branch 'feature/SmsWidget' Now, start committing on your feature. When done, use: git flow feature finish SmsWidget $ do some change $ git commit -am "your comment" ...
STEP3: 功能开发完毕,结束该分支
feature/SmsWidget> git flow feature finish Switched to branch 'develop' Already up-to-date. Deleted branch feature/SmsWidget (was 815ebd8). Summary of actions: - The feature branch 'feature/SmsWidget' was merged into 'develop' - Feature branch 'feature/SmsWidget' has been removed - You are now on branch 'develop'
如果你想在结束分支前Review你的改动
# 在feature分支下 feature/SmsWidget> git flow feature diff
如果多人共同开发新功能,你可以将该分支publish到中心仓库上
$ git flow feature publish feature/SmsWidget