Định Dạng
Cấu Trúc Commit Message
[optional scope]: [optional body] [optional footer(s)]
Giải Thích Các Phần
typeLoại thay đổi (feat, fix, v.v.)
scopePhần codebase bị ảnh hưởng (tùy chọn)
descriptionTóm tắt ngắn gọn ở thể mệnh lệnh
bodyGiải thích chi tiết (tùy chọn, sau dòng trống)
footerMetadata như BREAKING CHANGE hoặc tham chiếu issue
Quy Tắc
Thể mệnh lệnh"add feature" chứ không phải "added feature"
Type viết thườngfeat: chứ không phải Feat:
Không có dấu chấmDescription không kết thúc bằng "."
Dòng trốngPhân cách body/footer với description
Types
Type Cốt Lõi (Liên Quan SemVer)
featTính năng mới (tăng phiên bản MINOR)
fixSửa lỗi (tăng phiên bản PATCH)
Type Mở Rộng (Quy Ước Phổ Biến)
buildHệ thống build hoặc dependency ngoài
choreTác vụ bảo trì (không thay đổi src/test)
ciCấu hình và script CI
docsChỉ thay đổi tài liệu
perfCải thiện hiệu năng
refactorThay đổi code không sửa lỗi cũng không thêm tính năng
revertHoàn tác commit trước đó
styleĐịnh dạng, khoảng trắng (không phải CSS)
testThêm hoặc sửa test
Scope
Sử Dụng Scope
feat(auth): add OAuth2 login flow fix(parser): handle empty input gracefully docs(readme): update installation steps refactor(api): extract validation middleware
Hướng Dẫn Scope
Tên modulefeat(auth):, fix(parser):
Tên layerfeat(api):, fix(db):
Khu vực tính năngfeat(search):, fix(checkout):
Dependencybuild(deps):, chore(npm):
Bỏ qua nếu rộngKhông cần scope cho thay đổi xuyên suốt
Breaking Changes
Đánh Dấu Breaking Change
feat!: remove deprecated login endpoint feat(api)!: change response format to JSON:API fix!: drop Node 14 support
Breaking Change Dạng Footer
feat(api): change user endpoint response BREAKING CHANGE: response now returns array instead of object. Update client parsing.
Quy Tắc
! sau type/scopeKý hiệu tắt cho breaking change
BREAKING CHANGE:Token footer (luôn viết hoa)
BREAKING-CHANGE:Cũng hợp lệ (dạng gạch ngang)
Ảnh hưởng SemVerTăng phiên bản MAJOR
Bất kỳ type nàoBreaking change có thể áp dụng cho mọi type
Ví Dụ
Commit Đơn Giản
feat: add email notifications fix: prevent race condition in checkout docs: correct typo in contributing guide style: format with prettier refactor: simplify error handling logic
Có Scope
feat(blog): add comment threading fix(auth): refresh token before expiry test(api): add missing edge case coverage ci(github): add Node 20 to test matrix
Có Body và Footer
fix(parser): handle nested quotes correctly Previously, nested quotes caused the parser to enter an infinite loop. This adds a depth counter to prevent unbounded recursion. Closes #234
Footer
Các Token Footer
BREAKING CHANGE:Mô tả thay đổi API breaking
Closes #123Tự động đóng issue khi merge
Fixes #456Tự động đóng issue (tham chiếu fix)
Refs #789Tham chiếu issue không đóng
Reviewed-by: nameGhi nhận người review
Co-authored-by: nameGhi nhận đồng tác giả
Nhiều Footer
feat(api)!: redesign authentication flow Migrate from session-based to JWT auth. BREAKING CHANGE: /auth endpoints changed Closes #101 Refs #98, #99
Công Cụ
Commit Linting
npm install -D @commitlint/cli \ @commitlint/config-conventional echo "module.exports = { extends: \ ['@commitlint/config-conventional'] }" \ > commitlint.config.js
Công Cụ Phổ Biến
commitlintKiểm tra commit message theo quy ước
huskyGit hook (chạy commitlint khi commit)
commitizen (cz)Trình tạo commit message tương tác
standard-versionTự động changelog + tăng phiên bản
semantic-releasePipeline release hoàn toàn tự động
release-pleaseCông cụ tự động release của Google
Thiết Lập Commitizen
npm install -D commitizen \ cz-conventional-changelog npx commitizen init cz-conventional-changelog # Dùng: npx cz (hoặc git cz với alias)
Các Pattern Thường Gặp
Ánh Xạ Tăng Phiên Bản
fix:PATCH (1.0.0 → 1.0.1)
feat:MINOR (1.0.0 → 1.1.0)
BREAKING CHANGEMAJOR (1.0.0 → 2.0.0)
docs:, style:, v.v.Không tăng phiên bản
Nhóm Changelog
## [1.2.0] - 2026-03-27 ### Features - add email notifications (abc1234) ### Bug Fixes - prevent race condition (#123) (def5678)
Định Dạng Revert
revert: feat(blog): add comment threading This reverts commit abc1234def5678.