在團隊協做開發時,每一個人提交代碼時都會寫 commit message。webpack
每一個人都有本身的書寫風格,翻看咱們組的git log, 能夠說是五花八門,十分不利於閱讀和維護。git
通常來講,大廠都有一套的本身的提交規範,尤爲是在一些大型開源項目中,commit message 都是十分一致的。github
所以,咱們須要制定統一標準,促使團隊造成一致的代碼提交風格,更好的提升工做效率,成爲一名有追求的工程師。web
AngularJS 在 github上 的提交記錄被業內許多人承認,逐漸被你們引用。npm
type(scope) : subject
( 1 ) type(必須) : commit 的類別,只容許使用下面幾個標識:gulp
( 2 ) scope(可選) : 用於說明 commit 影響的範圍,好比數據層、控制層、視圖層等等,視項目不一樣而不一樣。vim
( 3 ) subject(必須) : commit 的簡短描述,不超過50個字符。
commitizen 是一個撰寫合格 Commit message 的工具,
遵循 Angular 的提交規範。性能優化
全局安裝 commitizen編輯器
npm install -g commitizen
進入項目文件夾,運行以下命令:grunt
commitizen init cz-conventional-changelog --save --save-exact
用 git cz
命令取代 git commit
(先使用git add),這時會出現以下選項:
( 1 )選擇 type
( 2 )填寫 scope(選填)
? What is the scope of this change (e.g. component or file name)? (press enter to skip) core
( 3 )填寫 subject
? Write a short, imperative tense description of the change: set a to b
完成,運行 git log
命令,查看咱們剛纔提交的 commit message,以下:
fix(core): set a to b
步驟以下:
在項目中創建 .git_template 文件,內容能夠自定義:
type: scope: subject:
運行以下命令:
git config commit.template .git_template // 當前項目 <!-- git config commit.template .git_template // 全局設置 -->
先使用 git add
添加代碼
使用 git commit
按照模板填寫
最後 git push
推送到遠端
第二章中提到的兩種業內廣泛使用的規範,都不徹底適合咱們。
第一種方式適合大型開源項目,咱們若是也照搬會比較麻煩,但咱們能夠借鑑 type(scope): subject 的提交格式,也算是與大廠同步;
第二種方式雖然自由,可是也不比較麻煩,要配置模板。
所以,咱們只模仿 type(scope): subject 的提交格式,不使用工具 or 模板校驗,靠你們自覺遵照便可。
type: description
type 是 commit 的類別,只容許以下幾種標識:
description 是對本次提交的簡短描述。
不超過50個字符。
推薦以動詞開頭,如: 設置、修改、增長、刪減、撤銷等