Trung BìnhGit iconGit

Conventional Commits là gì? Tại sao nên enforce bằng commitlint thay vì chỉ "agree" trong team?

Conventional Commits là convention format: type(scope): description. Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert.

Tại sao không chỉ "agree": agreement không có enforcement = mọi người quên hoặc bỏ qua khi deadline gần. Sau 3 tháng, git log trở thành "fix stuff", "update", "wip", "asdfgh".

Setup commitlint + husky:

bash
npm install --save-dev @commitlint/cli @commitlint/config-conventional husky
# commitlint.config.js:
module.exports = { extends: ["@commitlint/config-conventional"] }
# .husky/commit-msg:
npx --no -- commitlint --edit $1

Lợi ích thực tế:
- semantic-release tự động bump version và generate CHANGELOG từ commits
- git log --oneline readable: thấy ngay đây là feature hay fix
- PR title auto-generate từ commit message
- Breaking changes: feat!: hoặc BREAKING CHANGE: footer tự động trigger major version bump

Lưu ý: đừng reject commit của mọi người khi scope sai — chỉ enforce type và description format, để scope optional.

Xem toàn bộ Git cùng filter theo level & chủ đề con.

Mở danh sách Git