← Back to list

用 Git Hooks 改善開發

紀錄一下目前我對 Git Hooks 的使用程度

Phelix · 2021-12-11 06:32 · 0 claps · 1.4 min read
#git #git-hooks
Open on Medium ↗
Wiki topics: 🔓 · Open Source

#Git Hooks #DX

用 Git Hooks 改善開發

紀錄一下目前我對 Git Hooks 的使用程度

Git Hooks 大概分 Client Side, Server Side。 很字面的意思,Commit 的人的電腦跑的,和 Git Server上跑的。 到目前我都只有用 Client Side 來滿足需求,因此就只談這一部分。

Git 官網其實有對 Hooks 提供很詳盡的解釋,但是排版不太吸引我去閱讀。 https://git-scm.com/docs/githooks

因此就想在這紀錄一下我對 Hooks 的理解跟適用情境。

附上一張自製的 Flow 圖 (畫完後覺得我好像不用解釋了?)。

從用途上來分類

Commit前專案品質的檢查,或跑Code Lint : pre-commit

Commit Message 更改或驗證 : prepare-commit-msg, commit-msg

我個人覺得這兩個 hooks 用途很類似,唯一有差的就是 commit-msg 可以被 --no-verify 跳過這點。

Commit 後才要做的工作,像是上 Tag : post-commit

Push 前才要做的工作,不用在 Commit 完跑 : pre-push


메타데이터
post_id
feeb4660df9b
slug
用-git-hooks-改善開發-feeb4660df9b
url
https://medium.com/@.acedia/%E7%94%A8-git-hooks-%E6%94%B9%E5%96%84%E9%96%8B%E7%99%BC-feeb4660df9b
canonical_url
https://medium.com/@.acedia/%E7%94%A8-git-hooks-%E6%94%B9%E5%96%84%E9%96%8B%E7%99%BC-feeb4660df9b
author_url
https://medium.com/@.acedia
status
ok
fetched_at
2026-07-27 18:07:00