git commit規範化實踐

最近從svn轉到git進行代碼版本控制,今天瞭解了git commit規範化的一些知識後,寫此文章記錄下配置過程。vue

環境

編輯器使用的是vscode,項目框架是vue3.0node

規範化工具

規範化git commit消息的工具commitizen

# 將commitizen命令行安裝到全局
npm install -g commitizen

安裝完以後咱們就項目中引進改工具,就能夠規範commit行爲了。提交的命令爲git cz,若是仍是用git commit命令進行提交,那麼這個工具就不會起到什麼做用了。git

commitizen對commit規範化界面都是英文提示,這個時候我就想若是要漢化怎麼辦,這就有了下面一個工具的出現。github

安裝可定製的Commitizen插件cz-customizable

npm install cz-customizable --save-dev

安裝cz-customizable能夠配置自定義的commitizen配置文件,在自定義的配置文件中我就能夠對配置進行漢化npm

"config": {
    "commitizen": {
      "path": "./node_modules/cz-customizable"
    },
    "cz-customizable": {
      "config": "my.cz-config.js" // 這裏的文件名能夠自定義,可是改文件須要放置在項目的根目錄下
    }
  }

漢化完以後的效果是下面這樣:
json

版本發佈

進行commit規範化的好處是爲了提升團隊協做效率,使代碼閱讀性更強。還有另一個節省後期維護版本信息的成本。經過規範化commit行爲,咱們能夠經過自動化工具生成版本信息這樣極大的下降了維護成本,提升了工做效率。在這裏我使用的版本發佈工具是standard-version,固然還有conventional-changelog可使用。框架

standard-version能夠自動幫助咱們作如下幾件事情:編輯器

  1. 自動在數據中生成版本號
  2. 使用conventional-changelog更新 CHANGELOG.md
  3. 提交package.json (若是有) 和 CHANGELOG.md
  4. 給新版本打一個tag

首先是安裝standard-versionide

npm i standard-version --save-dev

安裝完成以後,執行standard-version命令,在控制檯能夠看到以下信息:
svn

能夠清楚的看到standard-version作了哪些事情。其中package.json和changelog.md文件是被自動提交了的。這樣在項目中生成了一個changelog文件

# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.3.2](http://112.80.40.2:11080/chenchent/cdss-acs/compare/v0.3.1...v0.3.2) (2019-07-25)



### [0.3.1](http://112.80.40.2:11080/chenchent/cdss-acs/compare/v0.3.0...v0.3.1) (2019-07-25)


### Bug Fixes

* 將commitizen使用本地配置文件 ([4accd0a](http://112.80.40.2:11080/chenchent/cdss-acs/commit/4accd0a))



## [0.3.0](http://112.80.40.2:11080/chenchent/cdss-acs/compare/v0.2.0...v0.3.0) (2019-07-25)

### Bug Fixes

- **changelog:** 生成新的 changelog 文件 ([17747cf](http://112.80.40.2:11080/chenchent/cdss-acs/commit/17747cf))

### BREAKING CHANGES

- **changelog:** 測試

## 0.2.0 (2019-07-25)

### Features

- **me:** 測試 ([64e596d](http://112.80.40.2:11080/chenchent/cdss-acs/commit/64e596d))

# 0.1.0 (2019-07-25)

### Features

- **me:** 測試 ([64e596d](http://112.80.40.2:11080/chenchent/cdss-acs/commits/64e596d))

因爲我習慣於使用node命令,因此最後我又將規範化跟版本生成的命令配置到了scripts中

"scripts": {
    "commit": "git cz",
    "changelog": "standard-version --dry-run && standard-version" 
# standard-version --dry-run只是用來打印要作的事情,並不會作實際的操做
  }

這就是我對git commit規範化的一些實踐。mark下來作一個記錄,但願能夠幫助到其餘人。

相關文章
相關標籤/搜索