আপনার Code Clean, Architecture Solid, Design Pattern-ও ঠিকঠাক follow করছেন। কিন্তু Git history খুললে দেখা যায়:
a7d29c1 final fix
b8e31a2 updated code
c9f42d3 fix bug
d0a53e4 changes
e1b64f5 final final fix
Interesting! :')
ধরুন, ছয় মাস পর production-এ একটা critical bug পাওয়া গেল। এখন আপনাকে identify করতে হবে কোন change-এর পর থেকে issue-টা শুরু হয়েছে।
Git history খুললেন, আর উপরের commit message-গুলো দেখলেন।
এখন কোন commit-এ কী change হয়েছে সেটা বের করতে প্রতিটা commit-এর diff inspect করা ছাড়া খুব একটা উপায় নেই।
অথচ একই history এমন হতে পারত:
a7d29c1 fix(auth): reject expired tokens
b8e31a2 perf(db): eliminate N+1 queries
c9f42d3 feat(user): add email verification
d0a53e4 refactor(api): extract error handler
এখানে code না খুলেও change-গুলোর purpose সম্পর্কে একটা clear ধারণা পাওয়া যাচ্ছে।
এই ছোট্ট difference-টাই একটা project-এর maintainability-তে বড় impact ফেলতে পারে।
কারণ Git commit message শুধু একটা message না, এটা আপনার project-এর engineering history-এর অংশ।
আর সেই history readable রাখা একটা ভালো engineering practice।
1. Git History শুধু Code Changes-এর Record না
Git একটা Distributed Version Control System। এটা আপনার project-এর changes track করে, previous state preserve করে এবং collaboration সহজ করে।
কিন্তু Git নিজে থেকে আপনার engineering decisions-এর context explain করতে পারে না।
ধরুন, কোনো একটা commit-এ database query restructure করা হয়েছে। Git আপনাকে দেখাতে পারবে কোন code remove হয়েছে, কোন code add হয়েছে। কিন্তু কেন ওই approach নেওয়া হয়েছে, সেটা সবসময় diff দেখে বোঝা সম্ভব না।
হয়তো previous implementation-এ performance issue ছিল। হয়তো concurrency-related bug fix করা হয়েছে। অথবা কোনো architectural constraint-এর কারণে implementation change করতে হয়েছে।
এই context-টাই একটা meaningful commit message preserve করতে পারে।
এটা বিশেষভাবে useful যখন:
- Production issue debug করতে হয়
- Code review করতে হয়
- Previous change revert করতে হয়
- নতুন engineer project-এ onboard করেন
- Release notes বা changelog generate করতে হয়
Git history যত readable হবে, unnecessary investigation তত কমবে। অবশ্য commit message ভালো হলেই debugging automatically হয়ে যাবে না। কিন্তু অন্তত investigation শুরু করার জন্য একটা meaningful direction পাওয়া যায়।
2. Conventional Commits: A Simple but Powerful Convention
Commit message লেখার জন্য widely used একটা standard হচ্ছে Conventional Commits। এর basic structure:
<type>(<scope>): <description>
[optional body]
[optional footer]
Example:
fix(auth): reject expired refresh tokens
Validate token expiration before issuing
new access tokens to prevent credential reuse.
Closes #142
এখানে:
fix- Change-এর typeauth- কোন component বা module-এ change হয়েছেreject expired refresh tokens- Short description- Body - Change-এর additional context
- Footer - Related issue বা metadata
Scope optional। Body এবং footer-ও optional।
অর্থাৎ, প্রতিটা commit-এ তিন-চার paragraph explanation লেখার দরকার নেই।
Simple change হলে এটুকুই যথেষ্ট:
git commit -m "fix(auth): reject expired tokens"
এবার commonly used type-গুলো দেখে নেওয়া যাক।
এখানে একটা important clarification:
সব type Conventional Commits specification-এর mandatory part না। feat এবং fix-এর special semantic meaning আছে। অন্য type-গুলো team convention অনুযায়ী ব্যবহার করা হয়।
Convention-এর মূল উদ্দেশ্য complexity বাড়ানো না, communication simplify করা।
3. What Makes a Commit Message Actually Meaningful?
শুধু Conventional Commits format follow করলেই একটা commit message meaningful হয়ে যায় না।
ধরুন:
fix(api): fix api
Technically format ঠিক আছে। কিন্তু information কতটুকু পেলেন? প্রায় কিছুই না! :')
একটা ভালো commit message লেখার সময় কয়েকটা principle follow করা যায়।
Be Specific, Not Verbose
Bad:
fix: update code
Better:
fix(api): prevent duplicate requests
Description এমন হওয়া উচিত যাতে reader দ্রুত change-এর purpose বুঝতে পারেন।
Use Imperative Mood
Commit subject-এ action-oriented verb ব্যবহার করা common practice।
- add
- remove
- update
- prevent
- extract
- optimize
Example:
feat(search): add date range filtering
এতে commit message-টা এমনভাবে readable হয় যেন commit apply করলে কী change হবে সেটা describe করছে।
Explain WHY When Necessary
সব commit-এ body দরকার নেই। কিন্তু কোনো change-এর পেছনে important technical decision থাকলে সেটা mention করা useful।
Example:
perf(cache): replace global lock with per-key locks
The global lock serialized unrelated cache
updates under high concurrency.
Per-key locking allows independent keys
to be updated concurrently.
এখানে শুধু কী change হয়েছে সেটা না, কেন হয়েছে সেটাও বোঝা যাচ্ছে।
আর future-এ কেউ implementation modify করতে গেলে এই context কাজে লাগবে।
Keep Changes Logically Focused
এক commit-এ unrelated feature, bug fix, documentation এবং infrastructure changes mix না করাই ভালো।
Instead of:
update project
Separate logical changes:
fix(auth): prevent token reuse
perf(db): optimize lookup queries
docs: update deployment guide
তবে One Commit, One Logical Change মানে One Commit, One File না।
একটা feature implement করতে একাধিক file modify হওয়া একদম normal।
4. Real-world Examples Across Different Engineering Domains
Commit message কোনো specific programming language বা framework-এর concept না।
আপনি Java, Go, Python, Rust, JavaScript, C++ কিংবা অন্য যেকোনো language ব্যবহার করুন Git history maintain করার principle একই।
কয়েকটা different engineering context দেখি।
API Development
feat(api): add cursor-based pagination
fix(api): return correct status for invalid input
Database Engineering
perf(db): add index for frequent lookups
fix(db): prevent duplicate records
Frontend Development
fix(ui): prevent duplicate form submissions
feat(ui): add keyboard navigation
Security Engineering
fix(auth): reject expired session tokens
fix(security): restrict unauthorized file access
Infrastructure & DevOps
ci: run tests on pull requests
build: enable multi-stage container builds
chore(infra): update health check configuration
Systems & Concurrency
fix(worker): prevent race condition in job queue
perf(core): reduce lock contention
Testing & Reliability
test(api): add timeout regression tests
fix(queue): retry failed jobs with backoff
খেয়াল করলে দেখবেন, কোন example-এ কোন framework ব্যবহার করা হয়েছে সেটা জানার দরকার হচ্ছে না। কারণ commit message implementation-এর প্রতিটা detail explain করার জায়গা না। এটার purpose হচ্ছে change-এর intent communicate করা।
5. Breaking Changes: When a Commit Can Affect Other Systems
ধরুন, আপনার একটা public API আছে।
আগে endpoint ছিল:
POST /api/v1/login
এখন সেটা replace করে করেছেন:
POST /api/v2/auth/login
এবং পুরোনো endpoint remove করে দিয়েছেন।
এখন existing clients update না করলে integration break করবে।
এটা একটা Breaking Change।
Conventional Commits-এ এটা এভাবে express করা যায়:
feat(api)!: remove legacy login endpoint
BREAKING CHANGE: Clients must migrate to
/api/v2/auth/login.
এখানে ! breaking change indicate করছে। BREAKING CHANGE footer-এ migration context দেওয়া হয়েছে।
Semantic Versioning follow করলে breaking changes সাধারণত major version release-এর সঙ্গে related।
যেমন:
1.4.2 -> 2.0.0
এ ধরনের change explicitভাবে communicate করা important, কারণ আপনার code শুধু আপনার system-এ impact ফেলছে না অন্য client বা service-ও affected হতে পারে।
6. AI-Assisted Development: More Code, More Responsibility
এখন একটু current development workflow-এর দিকে আসি।
AI coding assistants এবং coding agents-এর কারণে code generation, refactoring, debugging অনেক কিছুই আগের তুলনায় দ্রুত করা যাচ্ছে।
একটা agent-কে বললেন: "Optimize the order processing pipeline."
Agent ২০টা file modify করে দিল। এখন আপনি যদি কোনো review ছাড়াই commit দেন:
git commit -m "AI changes"
তাহলে technically commit হয়ে গেল।
কিন্তু কী optimize হয়েছে? কোন approach নেওয়া হয়েছে? কোনো behavior change হয়েছে কি না? Git history থেকে কিছুই বোঝা যাচ্ছে না।
আর AI-generated code মানেই correct code এমন assumption করাও risky।
Generated changes-এ unnecessary abstraction, logical bug, security issue কিংবা unrelated modification থাকতে পারে।
তাই AI-assisted development-এ একটা sensible workflow হতে পারে:
- Generated diff inspect করুন
- Changes-এর intent এবং implementation বুঝুন
- Relevant tests run করুন
- Unrelated changes separate করুন
- Meaningful commit message লিখুন
Example:
perf(queue): batch process pending jobs
Replace individual job fetches with batched
retrieval to reduce database round trips.
আর AI-generated commit message ব্যবহার করলে সেটাও verify করুন।
কারণ AI confidently ভুল explanation লিখতে পারে।
AI can generate the code. But understanding, reviewing and owning that code is still an engineering responsibility.
7. Automating Commit Standards
Team project-এ সবাই manually একই convention follow করবেন এমন guarantee নেই। এজন্য commit message validation automate করা যায়।
Commitlint
Commitlint commit message নির্দিষ্ট format follow করছে কি না validate করে।
Install:
npm install --save-dev @commitlint/cli @commitlint/config-conventional
commitlint.config.mjs:
export default {
extends: ["@commitlint/config-conventional"]
};
Test:
echo "feat(api): add pagination" | npx commitlint
Invalid message হলে validation error দেখাবে।
Git Hooks
Husky-এর মতো tool ব্যবহার করে commit করার সময় automatically validation run করানো যায়।
npm install --save-dev husky
npx husky init
Commit message validation hook:
echo 'npx --no -- commitlint --edit "$1"' > .husky/commit-msg
তবে local Git hooks bypass করা সম্ভব।
তাই critical team workflow-এ CI pipeline-এ validation enforce করা ভালো।
Automated Releases
Conventional Commits-এর আরেকটা useful application হচ্ছে automated release management।
Semantic Versioning-এর common mapping:
fix: PATCH
feat: MINOR
BREAKING CHANGE: MAJOR
Example:
1.2.3 -> 1.2.4 Bug fix
1.2.3 -> 1.3.0 New feature
1.2.3 -> 2.0.0 Breaking change
Semantic Release-এর মতো tool commit history analyze করে versioning, changelog generation এবং release publishing automate করতে পারে।
Actual behavior অবশ্য configuration এবং release policy-এর ওপর depend করে।
এখানেই structured commit messages শুধু readability না, automation-এর জন্যও useful হয়ে ওঠে।
8. A Practical Git Workflow
Commit করার আগে কয়েকটা command habit হিসেবে follow করতে পারেন।
Current changes check করুন:
git status
Unstaged changes inspect করুন:
git diff
Logically related changes stage করুন:
git add -p
Staged changes review করুন:
git diff --cached
Commit করুন:
git commit -m "fix(auth): reject expired tokens"
Detailed message দরকার হলে:
git commit
History inspect করতে:
git log --oneline --graph --decorate
Latest local commit amend করতে:
git commit --amend
তবে shared history rewrite করার আগে সতর্ক থাকবেন। বিশেষ করে অন্য developer already ওই commits-এর ওপর কাজ শুরু করলে history rewrite unnecessary conflict তৈরি করতে পারে।
9. Does Every Project Need Conventional Commits?
Short answer: No.
একটা ছোট personal project-এ simple descriptive commit message-ও যথেষ্ট হতে পারে। আবার বড় team, open-source library, multi-service system কিংবা automated release workflow-তে structured commit convention অনেক বেশি useful।
এখানে goal হচ্ছে না প্রতিটা project-এ blindly একটা standard enforce করা। Goal হচ্ছে project-এর size, collaboration এবং maintenance requirements অনুযায়ী একটা consistent approach maintain করা।
কারণ engineering-এর একটা গুরুত্বপূর্ণ অংশ হচ্ছে context অনুযায়ী right decision নেওয়া। শুধু কোনো practice popular বলেই সেটা সব project-এ equally necessary হয়ে যায় না।
Final Thoughts
Readable code, maintainable architecture, proper testing, meaningful documentation এবং clean version history সবকিছু মিলেই একটা sustainable engineering workflow তৈরি হয়।
তাই next time commit করার সময় git commit -m "final fix" লেখার আগে একবার ভাববেন। ছয় মাস পর এই commit-টা দেখলে আপনি নিজেই বুঝতে পারবেন তো কী change করেছিলেন?
নাকি নিজের Git history decode করার জন্য আবার AI agent লাগবে? :')
Write commits for the developer who will debug your code six months later. That developer might be you.
References & Further Reading
- Original inspiration: The Art of Writing Meaningful Git Commit Messages
- Conventional Commits
- Git Documentation
- Commitlint
- Husky
- Semantic Release
- [1] https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/
- [2] https://medium.com/front-end-weekly/how-to-write-good-git-commit-messages-like-a-pro-2c12f01569d9
- [3] https://kelvinromero.medium.com/writing-good-commit-messages-527679b1babb
Key takeaways
Be Specific, Not Verbose
Description এমন হওয়া উচিত যাতে reader দ্রুত change-এর purpose বুঝতে পারেন।
Explain WHY When Necessary
কোনো change-এর পেছনে important technical decision থাকলে সেটা mention করা useful।
Keep Changes Logically Focused
One Commit, One Logical Change মানে One Commit, One File না।
