Best Practices for Writing Good Commit message
Khem Raj October 30, 2024 #metaKeep it Short and Descriptive:
Start with a brief summary of the change (ideally 50 characters or fewer).
For example, "busybox: Fix memory leak in inittab applet." is better than “Fixing bug that caused login issues due to inittab utility by upgrading busybox to latest.”
Use the Imperative voice:
Write as if you’re instructing the code to do some action
"Add login feature," "Update documentation," "Remove deprecated API."
Explain Why, Not Just What:
For non-trivial changes, provide a longer explanation in the body of commit message.
Why did you make this change? What problem does it solve?
Separate the Subject from the Body:
Use the first line as a short summary, then include additional details below if needed. Keep lines within the body at 72 characters or fewer for readability.
Remember consistency is the key. Creating a commit message template and better yet making it a pre-commit hook to pre-populate commit message can go a long way.
Writing good commit messages might seem trivial, but it makes a big difference in keeping a project organized, comprehendable, and maintainable, which pays off as the codebase grows.