Skip to content

Instantly share code, notes, and snippets.

@tpai
Created February 15, 2016 07:51
Show Gist options
  • Save tpai/148b523d06dad5bc2857 to your computer and use it in GitHub Desktop.
Save tpai/148b523d06dad5bc2857 to your computer and use it in GitHub Desktop.

有效利用git brach特性的開發模型!

主要分成下列branch:

  • master (主要)
  • develop (開發)
  • feature (功能)
  • release (釋出)
  • hotfix (重大修正)

Ref: git-flow cheatsheet

# 初始化git flow braching model
git flow init
# 開新feature
git flow feature start FEATURE_NAME
# 結束feature
git flow feature finish FEATURE_NAME
# [協作] 發佈feature
git flow feature publish FEATURE_NAME
# [協作] 取得feature
git flow feature pull FEATURE_NAME
# 釋出階段 開版號
git flow release start VERSION_NAME
# [協作] 允許其他開發者提交 commit
git flow release publish VERSION_NAME
# 正式釋出
git flow release finish VERSION_NAME
# push tag to remote
git push --tags
# 重大修正 開版號
git flow hotfix start VERSION_NAME
# 打上patch後再次釋出
git flow hotfix finish VERSION_NAME

OS: 幹 我還是用UI好了啦 >>Sourcetree

1) Create branch

  • master branch的任何一個commit都要是可以發佈的正式版本。
  • branch命名盡量口語化以敘述句為主。(ex. account-auth, frontend-page, backend-add-post)

2) Add commits

  • 描述修正、增加/更改功能使用祈使句,如:fix, add/change。
  • 文章段落跟段落之間永遠要多空一行。(不然就會黏成一行很醜)

commit message撰寫官方建議:

用一句話總結本次commit的主旨

如需要進一步說明,請在三句話以內結束本段,可利用「因為發現了什麼問題所以用了什麼方法解決」的問答格式。

修正了哪些地方:

  - 使用者回報的bug 已用某方法解決

  - 內部測試的bug 已用某某方法解決
Short (50 chars or less) summary of changes.

More detailed explanatory text, if necessary.  Wrap it to about 72 characters or so.

Further paragraphs come after blank lines.

  - Bug from user report, fix it with some way.

  - Bug from alpha test, fix it with another solution.

Ref: Commit GuidelinesWriting Good Commit Messages

3) Pull Request

分成兩種模式:

  • Fork & Pull Mode: 常用於Open Source Project,公開Code讓大家提出想法、建議或你已經準備好讓某人review Code,好處就在於當有人提出PR的時候,專案管理員會收到通知,且隨時可以將修改merge進來。
  • Shared Repository Mode: 常用於工作室或小組織的Private Project,使用上沒有太大的差別,基本就是在merge之前用來code review跟提案修正的討論。

4) Discuss and review your code

PR的好處就在於code reviewer之間可以彼此交流,有時候一閃神忘了做某些修正或是提交的code有bug等等小事,都可以利用comments提醒project mantainer。

另外PR的comments是使用markdown語法,所以你可以嵌入圖片(image)、顏文字(emoji)、自動上色的程式區塊和其他的語法。

5) Merge and Deploy

當PR已經被完整review過而且該branch也通過測試,就可以merge回master branch上準備發佈了。

小技巧:如果在issues中有這次merge能解決的問題,可以在commit message中輸入「This fixes #32, resolve #67, and closes user/repo#11」,就會將issues #32、#67和位在user/repo中的issue #11都close掉。

Ref: Git Protocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment