The Quest Begins (The "Why")
Honestly, I used to treat commit messages like the optional side‑quest in an RPG—something you could skip if you were in a hurry. I’d slap together things like “fix bug” or “update file” and move on, trusting that the diff would tell the whole story.
Then one rainy Tuesday I was hunting down a regression that had crept into our payment flow. The bug was subtle: a stray negative sign in a tax calculation that only showed up for international orders. I opened git log, scanned the recent commits, and saw a string of messages that read like a grocery list:
fix typo
refactor service
add logging
update deps
None of them hinted at why the tax logic had been touched, let alone what the intended outcome was. I spent three hours stepping through code, only to discover that the offending line had been changed two weeks earlier in a commit titled “refactor service”. The author had meant to clean up a helper function but, in the process, flipped the sign of a multiplier. The commit message gave zero clue about the side‑effect, and the reviewer had missed it because the diff looked harmless.
That moment felt like watching the Death Star appear on the horizon—suddenly, the stakes were crystal clear. If we kept writing vague commits, we were basically inviting the next Imperial ambush. I decided it was time to learn the true power of a meaningful commit message.
The Revelation (The Insight)
The best practice that transformed my workflow is deceptively simple: Every commit message should answer the question “Why?”
Not “What did I change?” (the diff already shows that). Not “Which file did I edit?” (again, the diff). But why did I make this change? What problem was I solving? What decision led me to this particular solution? When you embed the intent into the message, future you (or a teammate) can instantly grasp the reasoning without digging through lines of code.
Think of it like the opening crawl of a Star Wars film: a few sentences that set the stage, explain the conflict, and give you the motivation to care about the ensuing battle. Without that context, you’re just watching lightsabers clang with no idea why the fight matters.
Wielding the Power (Code & Examples)
The Trap: Vague, “What‑Only” Messages
$ git commit -m "fix bug"
or
$ git commit -m "update tax.js"
These messages are the equivalent of a stormtrooper shouting “I’m here!”—they announce presence but give no intel. When you later run git log --oneline, you see a wall of noise that forces you to open each commit just to figure out what’s going on.
The Victory: Intent‑Focused Messages
Let’s rewrite the same change with the “Why?” mindset. Suppose we corrected the tax multiplier after discovering it caused negative totals for orders over $1000.
$ git commit -m "fix tax multiplier sign for international orders > $1000
The tax calculation inadvertently applied a negative multiplier when
the base amount exceeded 1000 USD, resulting in negative tax totals
for certain foreign transactions. This change flips the sign back to
positive and adds a unit test to guard against regression."
Notice the structure:
- A short, imperative headline (≤50 characters) that sums up the fix.
-
A blank line—mandatory for readability in tools like
git log --pretty=fuller. - A body that explains the why: the symptom, the root cause, and the reasoning behind the fix.
-
Optional footers (e.g.,
Fixes: #123,Closes #456) if you track issues.
If you prefer a one‑liner for trivial changes, still aim for the why:
$ git commit -m "add missing newline to prevent concatenation errors in log output"
Even a tiny tweak gets a rationale, which pays off when someone later wonders why that newline matters.
Why This Beats the Old Way
After adopting this habit, my git log became a readable changelog. During a recent release review, a new teammate pointed out a potential edge case in a feature flag. Instead of digging through three commits, they read the messages:
feat: enable beta flag for EU users
The feature flag was previously gated behind a internal
testing flag that only applied to US environments. EU
stakeholders requested early access, so we expose the flag
via a new config entry and update the docs.
They instantly understood the motivation, suggested a tweak, and moved on. No extra meetings, no wasted time.
Why This New Power Matters
When you consistently write why‑focused commit messages, you gain a few superpowers:
-
Faster debugging – You can
git blameorgit log -S <keyword>and immediately see the intent behind a change, not just the mechanical edit. - Better code reviews – Reviewers spend less time asking “What was the goal here?” and more time discussing whether the solution is sound.
- Self‑documenting history – Your repository becomes a narrative of decisions, making onboarding smoother and reducing knowledge loss when people leave.
- Confidence in refactoring – Knowing the why lets you safely modify code because you understand the constraints that shaped it.
In short, treating commit messages as the story of your code’s evolution transforms a noisy log into a reliable compass.
Your Turn to Embark
Ready to give your commits the force they deserve? Next time you’re about to hit git commit -m "fix thing", pause. Ask yourself: Why am I making this change? Write that answer down, keep the headline short, and let the body tell the tale.
I’d love to hear how it goes—share your favorite “why” commit message in the comments, or tell me about a time a clear message saved you from a production nightmare. May your commits be clear, your history be enlightening, and your bugs be few! 🚀
Top comments (0)