Writing good commit messages is crucial for maintaining a clear and understandable project history. Proper commit messages help other developers understand the context and reasoning behind changes, making collaboration easier and more efficient. Here are 5 rules for writing better commit messages, along with examples of good and bad commit messages.
1. Write in English, because you often work in international teams
❌ Bad: Text in your language
✅ Good: Fix user login issue
2. Start with a verb in the imperative mood
❌ Bad: Fixing user login issue
✅ Good: Fix user login issue
3. Be concise
❌ Bad: This commit addresses an issue with the user login functionality where users were unable to log in due to an error in the authentication module.
✅ Good: Fix error in user authentication
4. Be specific, not vague like "change function"
❌ Bad: Change function
✅ Good: Update function to handle edge cases in user input
5. Provide context to show what changes affect
❌ Bad: Optimize code
✅ Good: Optimize data processing function
Bonus: 25 Verbs for Better Commits
Don’t just use "Fix". Use these verbs to improve the quality of your commit messages:
- Update
- Modify
- Amend
- Enhance
- Adjust
- Refine
- Tweak
- Polish
- Upgrade
- Refactor
- Optimize
- Patch
- Improve
- Fix
- Add
- Remove
- Implement
- Clean
- Restructure
- Streamline
- Correct
- Expand
- Simplify
- Secure
- Document
These verbs can help make your commit messages more descriptive and meaningful, providing clearer context for your changes.
Conclusion
Writing good commit messages is an important skill for any developer. Clear, concise, and descriptive commit messages make it easier to understand and collaborate on a project. By following these rules and learning from good and bad examples, you can improve the quality of your commit messages and contribute to a more maintainable and understandable codebase.
Top comments (0)