Skip to content

Latest commit

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..

README.md

commitizen and pre-commit 教學

Youtube Tutorial - commitizen 和 pre-commit 套件介紹

今天要介紹兩個東西, 分別是 commitizen 和 pre-commit

commitizen

commitizen 簡單說就是規格化 commit, 不然大家 commit 都亂打 😅

文件可參考 commitizen

pip install -U commitizen

安裝完後, 當我們 git add . 完之後,

執行執行 cz commitcz c 即可

img

接著你會看到要你輸入一些資訊(這些可以依照你們的團隊決定)

img

img

那接下來可能會遇到一個問題,

就是會不會忘記執行 cz c, 然後用一般的 commit 方式,

答案是肯定會忘記的 😄

所以有了以下的 pre-commit

pre-commit

文件可參考 pre-commit

pip install pre-commit

之後, 建立一個 .pre-commit-config.yaml 放在目錄底下,

內容填入

repos:
- repo: https://github.com/commitizen-tools/commitizenrev: v3.29.0hooks:
- id: commitizen
- id: commitizen-branchstages: [commit-msg]
- repo: https://github.com/pre-commit/pre-commit-hooksrev: v4.6.0hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python/blackrev: 24.8.0hooks:
- id: black
- repo: https://github.com/pycqa/flake8rev: 7.1.1hooks:
- id: flake8
- repo: https://github.com/crate-ci/typosrev: v1.24.6hooks:
- id: typos

這邊加入 pre-commit-hooks,

這裡有不少可以直接用的工具.

最後安裝你的 git hook scripts

pre-commit install --hook-type commit-msg

也可以直接執行以下一次全部安裝

pre-commit install

Install the git hook scripts

img

這樣子當你下次忘記用 cz c 執行 commit,

而是用一般的 commit 時, 就會跳出錯誤提醒你

( 第一次會慢一點, 之後就會很快了 😄 )

img

不只有 commitizen 可以用在 pre-commit,

像是 flake8black 這些很多都可以,

簡單說, 你可以把他想成是多一層檢查這樣 😄