Commit Message Techniques Nobody Teaches

Commit Message Techniques Nobody Teaches

Good commit messages are the difference between finding a bug's origin in five minutes versus two hours. Yet most developers treat them as annoying formalities.

What should actually go in a commit message?

The why, not the what. Your diff shows what changed. The message explains why you made that decision. "Fixed login bug" tells me nothing six months later. "Added null check in auth because Facebook OAuth returns empty email for some accounts" - now I understand the context when this code breaks something else.

How detailed should commit messages be?

First line: summary under 50 characters. Then a blank line. Then as much detail as future-you needs to understand the change. I regularly write 5-6 line commit bodies for tricky bugs. Seems excessive until that code causes a production issue and the commit message has the exact explanation you need.

Should every commit reference a ticket number?

Only if your team actually uses them for tracking. Mandatory ticket numbers in commits sounds professional but usually just means messages like "PROJ-1234: updates" that provide zero information. Better to write useful descriptions.

What about conventional commits with types like feat: or fix:?

They work great if you're generating changelogs automatically or have tooling that parses them. Otherwise, they're just ceremony. The important part is consistency within your team.

How do I write messages for work-in-progress commits?

Be honest. "WIP: rough draft of caching layer" is fine. You can always squash and rewrite before merging. Some developers commit every twenty minutes with terrible messages, then interactive rebase into clean commits before the pull request. Perfectly valid workflow.

Can I change commit messages after pushing?

Technically yes with git commit --amend or rebase, but you'll need to force push. Fine on feature branches, never do it on shared branches like main. The confusion isn't worth it.

Cookie Preferences

We use cookies to enhance your browsing experience and analyze site traffic. Choose your preferences below.

Required for basic site functionality. Always enabled.

Help us understand how visitors interact with our site.

Used to deliver personalized content and advertisements.