Writing Good Commit Messages
A commit message explains what changed and why. Good commit messages make it much easier for you and your teammates to understand project history months or years later.
A common convention is a short summary line under 50 characters, written in the imperative mood (e.g., "Fix bug" not "Fixed bug"), followed by an optional blank line and a more detailed body if needed.
git commit -m "Short summary"
git commitWriting a good summary
Keep the first line short and specific, such as "Fix null pointer in login form" rather than vague messages like "fix stuff" or "updates".
Adding a detailed body
For complex changes, run `git commit` without -m to open your editor, write a summary line, leave a blank line, then explain the reasoning in more detail below.
git commit -m "Fix crash when cart is empty"[main 9c2e1aa] Fix crash when cart is emptyA clear, specific summary describes exactly what the commit fixes.
git commit -m "Refactor auth module" -m "Splits login and signup logic into separate files for clarity."[main 4d1f0bb] Refactor auth moduleUsing two -m flags creates a summary line and a longer body message.
Key points
- Good commit messages explain what changed and why.
- Keep the summary line short and use the imperative mood.
- Avoid vague messages like 'fix stuff' or 'updates'.
- A blank line separates the summary from a detailed body.
