1. Cấu trúc cơ bản của Commit Message
Commit Message thường có cấu trúc như sau
<Type>(Scope)!: (Subject)
- Type: required, xác định loại thay đổi như
feat,fix,refactor - Scope: optional, chỉ ra phần nào codebase ảnh hưởng như
api,ui,auth. Đặt trong dấu() !(Break Change): optional. Báo hiệu rằng đây là một thay đổi phá vở tương thích. (Quan trọng, nghiêm trọng), ít dùng lắm.- Subject: required. Mô tả ngắn gọn, thường không quá 50 ký tự.
2. Type Prefixes
Dưới đây là các tiếp đầu ngữ (type) thông dụng theo Conventional Commits:
| Type | Commit Type | Example |
|---|---|---|
feat | Thêm một tính năng mới (Feature). | feat(auth): thêm đăng nhập bằng Google |
fix | Bug fix. | fix(core): fix convert date to string |
refactor | refactor code, no change features . | refactor(utils): using Extension Methods |
chore | maintain: update dependencies, config build. | chore: update phiên bản npm lên 10.1 |
docs | Documentation. | docs(readme): thêm hướng dẫn cài đặt local |
style | code style: remove trailing spaces | style(layout): áp dụng prettier cho toàn bộ css |
test | Tests | test: thêm unit test cho chức năng giỏ hàng |
perf | Thay đổi cải thiện hiệu suất (Performance). | perf(image): tối ưu hóa thuật toán nén ảnh |
build | Build: npm, dotnet | build: cập nhật webpack.config.js |
ci | (CI) như GitHub Actions, Jenkins. | ci: thêm job kiểm tra linting tự động |
3. Git Command
- Create a feature branch
git checkout -b feature/oauth-integration
- Pull codes
git pull --rebase
- Merge master into your branch
git pull --rebase
git rebase master
- Git push
git push --force-with-lease
4. Notes when commit
- Do not commit: token, password, secret keys, public API
- Should use environment variables