📱 Học IELTS miễn phí: App IELTS 6.0

Giới Thiệu

Bạn mở git log và thấy:

fudawipoaixdnapaebtueg

😱 Không ai hiểu bạn đã làm gì, kể cả chính bạn 3 tháng sau.

So sánh với:

ffrdieeoxafc(tasa(c:udttaouhsrp)h(d:baaoptraieer)sd:Ao)Pl:eIvxeatrdratdatocekrt-eelnavilame-lixtitpidiimanretgaitnosioneotcniltfoicigohcineacctikitnooonRnmEbiAradDeddMfglEreeewsahre

Rõ ràng, dễ tìm, chuyên nghiệp. Đó là sức mạnh của commit message chuẩn.

Bài này hướng dẫn bạn viết commit message chuẩn Conventional Commits, bằng tiếng Anh tự nhiên, kèm từ vựng và mẫu câu thực tế.


1. Cấu Trúc Commit Message Chuẩn

1.1 Format cơ bản

<[[tbfyoopdoeyt>]e(r<]scope>):<subject>
PhầnBắt buộc?Mô tả
type✅ CóLoại thay đổi: feat, fix, docs…
scope❌ KhôngPhạm vi ảnh hưởng: auth, api, ui…
subject✅ CóMô tả ngắn gọn (< 72 ký tự)
body❌ KhôngGiải thích chi tiết (tại sao, như thế nào)
footer❌ KhôngBreaking changes, issue references

1.2 Ví dụ đầy đủ

fPaTtCernholaediotvses(isnecotcssauiourslmr#tllme1)yi2:,ptq3ru4auoaadscdndeedtresiqsdtucyactlnooiituesilcntdhtbye-escstvekiwatodelueeiqtndu,aaan1tncditaaoiusnntsedyirbnv9etge9for.op-r0aseyiomdcreehnentvceakgeloariutrdtioavrtesi.onnumbers

2. Commit Types — Bảng Từ Vựng

TypePhát âm IPANghĩaKhi nào dùng
feat/fiːt/tính năng mớiThêm feature mới cho user
fix/fɪks/sửa lỗiFix bug, hotfix
docs/dɒks/tài liệuCập nhật README, API docs
style/staɪl/định dạng codeIndent, spacing, formatting (không đổi logic)
refactor/ˌriːˈfæk.tər/tái cấu trúcĐổi code nhưng không đổi behavior
test/test/kiểm thửThêm/sửa unit test, integration test
chore/tʃɔːr/việc vặtBuild config, CI, dependencies
perf/pɜːrf/hiệu năngCải thiện performance
ci/siː aɪ/CI/CDThay đổi CI pipeline, GitHub Actions
build/bɪld/build systemWebpack, Vite, Docker config
revert/rɪˈvɜːrt/hoàn tácRevert commit trước đó

3. Viết Subject Line — Động Từ Nên Dùng

3.1 Quy tắc quan trọng

Subject line luôn dùng imperative mood (câu mệnh lệnh):

❌ Sai✅ ĐúngGiải thích
Added login featureAdd login featureImperative mood
Fixes the bugFix the bugKhông chia thì
Adding validationAdd validationKhông dùng -ing
Fixed authenticationFix authenticationKhông dùng past tense

💡 Mẹo nhớ: Hoàn thành câu “This commit will ___” — phần blank chính là subject:

  • This commit will add login feature
  • This commit will added login feature

3.2 Động từ phổ biến trong commit

Động từPhát âm IPANghĩaVí dụ
add/æd/thêmadd user avatar upload
remove/rɪˈmuːv/xóa bỏremove deprecated API endpoints
update/ʌpˈdeɪt/cập nhậtupdate error handling logic
fix/fɪks/sửafix null pointer in search query
refactor/ˌriːˈfæk.tər/tái cấu trúcrefactor auth middleware
implement/ˈɪm.plɪ.ment/triển khaiimplement rate limiting
improve/ɪmˈpruːv/cải thiệnimprove query performance
replace/rɪˈpleɪs/thay thếreplace moment.js with date-fns
migrate/ˈmaɪ.ɡreɪt/di chuyểnmigrate database to PostgreSQL
extract/ɪkˈstrækt/tách raextract validation to shared util
rename/ˌriːˈneɪm/đổi tênrename UserService to AuthService
simplify/ˈsɪm.plɪ.faɪ/đơn giản hóasimplify error response format
optimize/ˈɒp.tɪ.maɪz/tối ưuoptimize image lazy loading
handle/ˈhæn.dl/xử lýhandle edge case for empty cart
prevent/prɪˈvent/ngăn chặnprevent duplicate form submission
resolve/rɪˈzɒlv/giải quyếtresolve merge conflict in config
deprecate/ˈdep.rɪ.keɪt/đánh dấu lỗi thờideprecate legacy payment API
bump/bʌmp/nâng versionbump lodash to 4.17.21
configure/kənˈfɪɡ.ər/cấu hìnhconfigure CORS for production
ensure/ɪnˈʃɔːr/đảm bảoensure graceful shutdown on SIGTERM

4. Viết Body — Giải Thích Chi Tiết

Khi thay đổi phức tạp, thêm body để giải thích WHY (tại sao) và HOW (như thế nào).

4.1 Mẫu body hay dùng

Giải thích nguyên nhân:

fTt"wTaihrPehnxeaariy(nyespps"naaacfeyycmriwmmtuexeeilapnnottaattniedy)spddm:sl.seebenpreatrvftneioirvcrmieeeeedqnseutwcmeardpsdseuotuaet.pnteloitnitnoccgyacsthalkeeoecnwyckehiwrcanehrgosegnpcefeokso.nrsboWeeneh,fxeorindresuettuprislpyneirgrcosacpteecesnlsdiciichnnkaggerdges

So sánh trước-sau:

rBaAteenfhffdtraoeocrtruteh:go:ehrC(Nclmaeoeipsdaditend)el:ddaeiswrcfyaeafnrplicellc/.abuacalwectakicsttaolmflatlbdeoaeswctke.w-ribrtaohsrecdheanantudrtlahilniwgzietidhnceaorsnrysonircs/thaeawnnatdilting

Liệt kê thay đổi:

fC----ehaaRASAtnedhd(gpdoddelwasades:cacxhetopbemoobpraaratrrardnit)cgso:heoanCrrpSetiwVdciewktfsiehuitrnghpcn(rti7eiandvont,inaeoalr3ulya0sitcdtit,pyciesv9re0idovl,deirncveuisectwhoamr)t

4.2 Từ nối hữu ích trong body

Cụm từNghĩaVí dụ
Previously, …Trước đây, …Previously, the cache TTL was hardcoded.
This commit …Commit này …This commit extracts the logic to a config file.
This is needed because …Cần thiết vì …This is needed because the old API is deprecated.
Without this change, …Nếu không thay đổi, …Without this change, the build fails on Node 20.
This addresses …Điều này giải quyết …This addresses the race condition in #456.

5.1 Tham chiếu issue

fCRilexof(ssaeus#t4h#5)76:8,9h#a1n2d3leexpiredrefreshtokengracefully
KeywordNghĩaTác dụng trên GitHub
Closes #123Đóng issue #123Tự động close issue khi merge
Fixes #123Sửa issue #123Tự động close issue
Refs #123Tham khảo issue #123Tạo link nhưng không close
Resolves #123Giải quyết issue #123Tự động close issue
Related to #123Liên quan đến #123Chỉ tạo link

5.2 Breaking changes

fBABAMeRlefiaElftgtAoer(KerraaIne:tpNd:iiGpo)o{{n:CiHn""gcAtuduhNssaiaGetdnEnraeg:o"":ew::Tdrhr{{oeeecst""spAunt/oPraymnInmpiseegerd""rea::afsttopa""iroJuomniosnasnhe-tenrvJ""3tsS,.otO}mrN"dJu:}aScAtOtPtNuIr:riAefbPouIhrtamessaspt"ec.:cha{ng"enda.me":"John"}}}

6. Lỗi Thường Gặp — Và Cách Sửa

6.1 Message quá chung chung

❌ Sai✅ Đúng
fix bugfix(cart): resolve negative quantity validation
update coderefactor(auth): extract JWT verification to middleware
changesfeat(search): add autocomplete suggestions
WIPfeat(upload): add drag-and-drop file upload (WIP)

6.2 Message quá dài

❌ Sai✅ Đúng
fix the bug where users cannot login when they use special characters in their password because the validation regex was wrongfix(auth): allow special characters in password validation

💡 Subject line tối đa 72 ký tự. Chi tiết để trong body.

6.3 Dùng sai thì / mood

❌ Sai✅ Đúng
Added new endpointAdd new endpoint
Fixes login issueFix login issue
Adding dark modeAdd dark mode

6.4 Mix ngôn ngữ

❌ Sai✅ Đúng
fix: sửa lỗi đăng nhậpfix(auth): resolve login validation error
feat: thêm chức năng uploadfeat(upload): add file upload with drag-and-drop

7. Quick Reference — Mẫu Commit Theo Tình Huống

🐛 Fix bugs

ffffiiiixxxx((((auaduipbt)i)h:):)::cpohrrraeernvsedeoclnltetveancluotilnoglnkneemrcneetnsirtpoeonfonrfspeeosmohofldrraoealmxcheopanaucysommtnoeidbnoiitntlieguoanndtdeeevwriacyleosad

✨ New features

ffffeeeeaaaatttt((((sneieox1atp8rioncfr)hit:)c):a:atdaiaddoddndJ)af:bpuuazilnzmkeypslCeseSemVlaearnenctxghpuroawergiatetlh-fstoutirpymppetoorrpattunosslhaecrntaointocinefihciasttioornys

🔧 Refactoring

rrrreeeeffffaaaaccccttttoooorrrr((((aactpuoeitns)hft:)is:g)r):ec:poelnmxasitcogrelraiacRdttEaeStsTefhracdoraumelpdll.siefcniwavxitttetuhorveGaYsrlAaiMtpdLohaQtccLiooonnqnffuitelgerousigrteiasction

📝 Documentation

ddddooooccccssss::((raauepdpaiddd)am:AtePe)aI:dddaeaupdOtldphoeeybnnmaAtedPingIcteasstipinaeosncntdrfgucoucoritnditveor3nisbeunftdoiprnogiKnugtbuseirdneeltienses

🔨 Chores & maintenance

cccbhhiuoo:irrleead:(d:dduecppaogsunr)tfa:oidmgebauutrdmeeepdpteasrnxeediceeou-nsrscihiftaeryksoimsntcgo0a.nfl2noa7irtnetgpsortto1ods.ut6PcaRtbilpoeinpvebeluriisnliedosns

8. Practice — Viết Commit Message 📝

Bài 1: Viết commit message cho các tình huống sau

  1. Bạn thêm nút “Dark Mode” vào trang Settings.
  2. Bạn sửa lỗi user không logout được trên Safari.
  3. Bạn cập nhật README thêm hướng dẫn cài đặt Docker.
  4. Bạn đổi tên bảng users thành accounts trong database.
  5. Bạn nâng phiên bản React từ 18 lên 19.
📖 Đáp án gợi ý
  1. feat(settings): add dark mode toggle
  2. fix(auth): resolve logout failure on Safari
  3. docs(readme): add Docker installation guide
  4. refactor(db): rename users table to accounts
  5. chore(deps): upgrade React from v18 to v19

Bài 2: Sửa commit message sai

  1. Fixed the bug in login page
  2. update
  3. add some new features and fix some bugs and update docs
  4. feat: thêm chức năng tìm kiếm sản phẩm
📖 Đáp án gợi ý
  1. fix(auth): resolve login page validation error (imperative mood, thêm scope)
  2. refactor(config): update environment variable naming (cụ thể hơn)
  3. Tách thành 3 commits riêng:
    • feat(search): add product search with filters
    • fix(cart): resolve quantity update on mobile
    • docs: update API endpoint documentation
  4. feat(search): add product search functionality (viết bằng tiếng Anh)

Kết Luận

Commit message tốt không phải để “cho đẹp” — nó giúp bạn debug nhanh hơn, review dễ hơn, và chứng minh năng lực khi ai đó xem git log của bạn.

3 quy tắc vàng:

  1. 🏷️ Type + scope: Phân loại rõ ràng (feat, fix, docs…)
  2. ✍️ Imperative mood: Viết dạng mệnh lệnh (add, fix, remove)
  3. 📏 Ngắn gọn, cụ thể: Subject < 72 ký tự, chi tiết để trong body

Bài liên quan:


Bắt đầu từ commit tiếp theo — hãy viết message chuẩn nhé! Team bạn sẽ cảm ơn đấy 😄 🔖