come from :http://blog.csdn.net/maosidiaoxian/article/details/22799157
對git不熟悉的我,經常把git提交搞得很亂,導致在master上有許多無用的commit,最終決定好好地看一下git的使用教程,卻不小心發現了還有一個git-flow的工具可以幫助我管理好git項目的代碼。
git-flow在ubuntu上使用比較簡單。首先安裝,可以通過apt-get來獲取。命令如下:
sudo apt-get install git-flow
如果是在windows下,可以參考這篇文章進行安裝:http://my.eoe.cn/sunxun/archive/158.html
如果你的git已經裝好,則方便多了,下載下面兩個地址的文件,並解壓出getopt.exe和libintl3.dll放到git的安裝目錄的bin目錄下。
http://sourceforge.net/projects/gnuwin32/files/util-linux/2.14.1/util-linux-ng-2.14.1-bin.zip/download
http://sourceforge.net/projects/gnuwin32/files/util-linux/2.14.1/util-linux-ng-2.14.1-dep.zip/download
然後檢出github上gitflow項目,如下命令:
- git clone --recursive git://github.com/nvie/gitflow.git
git clone --recursive git://github.com/nvie/gitflow.git
進入並執行裏面的contrib\msysgit-install.cmd,提示覆製成功,就可以了。
接下來是初始化項目。我在我原來的git項目上執行以下命令來進行初始化:
- git flow init
git 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/]
- Release branches? [release/]
- Hotfix branches? [hotfix/]
- Support branches? [support/]
- Version tag prefix? []
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/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
完成之後,通過git branch 命令,可以看到它爲我們新建好了一個develop的分支。
接下來我將繼續使用,這篇筆記再慢慢補充。
修復一個bug。
- git flow hotfix start 3
git flow hotfix start 3
它會創建一個基於master的分支hotfix/3,並切換到當前分支。
當修復完成後,可以執行以下命令:
- git flow notfix finish 3
git flow notfix finish 3
增加一個功能特性
- git flow feature start demo
git flow feature start demo
它會創建一個分支feature/demo,並切換到該分支。
- git flow feature finish demo
git flow feature finish demo
它會有feature/demo分支合併到develop分支,然後切換回develop分支,並刪除feature/demo分支。
功能完成,要合併到主分支,這時可以執行
- git flow release start v0.7.0
git flow release start v0.7.0
它會創建一個release/v0.7.0分支,並切換到該分支。
然後在這裏進行測試。如果測試沒問題,則執行以下命令:
- git flow release finish v0.7.0
git flow release finish v0.7.0
它會將release/v0.7.0分支的內容合併到master分支和develop分支,並且打上tag v0.7.0,然後刪除release/v0.7.0分支。