Crafting the Perfect Commit Message
3. Subject Line First, Then the Body
Okay, let's talk about commit messages. It sounds simple, but it's surprisingly important. A well-written commit message is like a mini-document that explains why a change was made, not just what was changed. Think of it as leaving breadcrumbs for future developers (including yourself!).
A good commit message follows a few conventions. First, it has a subject line that's a concise summary of the change (50 characters or less is a good guideline). This subject line should complete the sentence "This commit will..." So, instead of "Fixed bug," try "This commit will fix bug where user could enter negative age." Then, if necessary, include a more detailed body that explains the context of the change, the reasoning behind it, and any potential side effects.
The body of your commit message should be separated from the subject line by a blank line. Use imperative mood in the subject line (e.g., "Fix," "Add," "Remove" instead of "Fixed," "Added," "Removed"). This makes the commit message sound like an instruction rather than a description. Try to keep lines in the body of your message to 72 characters or less to improve readability.
Avoid vague commit messages like "Updated files" or "Minor changes." These are useless! Instead, be specific and explain the why behind the change. "Refactored user authentication module to improve security" is much better. If you're fixing a bug, include the bug number or a link to the issue tracker. The goal is to make it as easy as possible for someone to understand the commit without having to dig through the code itself.