Git-Flow 使用筆記

為什麼使用Git Flow?

Git在開發上非常方便,但也因為可以很方便的把各自的負責的部份切開,一旦 commit 和維護的人一多,就很容易顯得 branch 非常的雜亂,主要版本如果過度的小部 commit ,就會顯得很沒意義,因為並沒有辦法很快速的看出版本切割在哪(雖然可以用 tag 之類的),所以 Git Flow 的概念就是將主要的 branch 分為 masterdevelop,master就是最後的發佈版本,所有維護者在發佈前的都是對develop進行操作,這樣就不會讓發佈版本的 branch 看起來過度雜亂。

安裝Git Flow

Git Flow 並不是本來就在 Git 裡面的功能,所以需另外安裝(GitHub連結),有很多 Git 的 GUI 操作軟體本身就可以操作Git Flow 就不用另外再安裝。

主要 branch

  • master: 主要版本,只接受 develop 和 Release 的 merge
  • develop: 所有 Feature 開發都從這分支出去,完成後merge回來

支援 branch

  • Feature: 從 develop 分出來,做功能開發
  • Release: master 發佈後修 bug 用,完成後 merge 回 master 和 develop
  • Hotfix: 火燒屁股的 bug 必須馬上解決時用,完成後 merge 回 master 和 develop

操作Git Flow

安裝 Git Flow 進專案

git flow init [-d]

-d 依照預設值建置建置

原始的建置如下:

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? [] 

就是設定名稱的部份,但如果沒特殊需求,還是ㄎ照原本就好,在承接上才不會有太大的問題。

建立分支(feature/release/hotfix)

  1. feature

    git flow feature
    git flow feature start <name> [<base>]
    git flow feature finish <name>
    

    <base>預設是develop
    提交 feature branch 至 remote:

    git flow feature publish <name>
    git flow feature pull <remote> <name>
    
  2. release

    git flow release
    git flow release start <release> [<base>]
    git flow release finish <release>
    

    <base>預設是develop

  3. hotfix

    git flow hotfix
    git flow hotfix start <release> [<base>]
    git flow hotfix finish <release>
    

    <base>預設是master

  4. support

    git flow support
    git flow support start <release> <base>
    

    <base>預設是master

實驗性的 support branch

在 github 文件上發現這一個 branch,但很多教學文都沒有提到這一個,後來查了這一篇,裡面說到(有誤請指教):

git flow support
Overview

This is still a very experimental feature of Gitflow, so you should use it with caution. I’m going to go through it so you understand what this branch is for and how it should be used. As mentioned previously, this is the branch that you should create when and only when you have to support an older version of the software. This is generally for some big lazy client that don’t want to upgrade for some obscure reason, but who has enough money to keep management happy to keep assigning resources to this type of development even though it may in fact cause some trouble in other places. If you’re getting the idea that I don’t think this is ever a good idea, you’re right. Software evolves to quickly for us to be kept back by clients such as these, but alas they are the clients and they do keep us in business :-).

翻譯:
這是gitflow一個實驗性的功能,所以在使用上必須非常謹慎。接下來我們將講解如何去使用他。先前提到,當你必須去支援較舊的版本時,就必須使用這個方法去建立分支,通常會發生在一些懶得升級的用戶端,但他們卻又有預算可以分配給這些開發,
即時他們知道這可能會導致一些問題的發生。如果你要這樣相容舊版本是對的,但我不認為他是一個好主意。軟體在現今變化速度很快,我們必須阻止客戶繼續停留在舊版本上,但很無奈的是,出錢的說話最大。

Getting Started – Git-Flow http://yakiloo.com/getting-started-git-flow//…

參考連結

Git flow 教學

git-flow cheatsheet

Comments

comments powered by Disqus