Youtube Tutorial - commitizen 和 pre-commit 套件介紹
今天要介紹兩個東西, 分別是 commitizen 和 pre-commit
commitizen 簡單說就是規格化 commit, 不然大家 commit 都亂打 😅
文件可參考 commitizen
pip install -U commitizen
安裝完後, 當我們 git add .
完之後,
執行執行 cz commit
或 cz c
即可
接著你會看到要你輸入一些資訊(這些可以依照你們的團隊決定)
那接下來可能會遇到一個問題,
就是會不會忘記執行 cz c
, 然後用一般的 commit 方式,
答案是肯定會忘記的 😄
所以有了以下的 pre-commit
文件可參考 pre-commit
pip install pre-commit
之後, 建立一個 .pre-commit-config.yaml 放在目錄底下,
內容填入
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.29.0
hooks:
- id: commitizen
- id: commitizen-branch
stages: [commit-msg]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python/black
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/crate-ci/typos
rev: v1.24.6
hooks:
- id: typos
這邊加入 pre-commit-hooks,
這裡有不少可以直接用的工具.
最後安裝你的 git hook scripts
pre-commit install --hook-type commit-msg
也可以直接執行以下一次全部安裝
pre-commit install
Install the git hook scripts
這樣子當你下次忘記用 cz c
執行 commit,
而是用一般的 commit 時, 就會跳出錯誤提醒你
( 第一次會慢一點, 之後就會很快了 😄 )
不只有 commitizen 可以用在 pre-commit,
像是 flake8
black
這些很多都可以,
簡單說, 你可以把他想成是多一層檢查這樣 😄