Commit Message Convention

Aldy Kusuma

I Putu Aldy Cahyakusuma

Software Engineer

1 min read min read

Jan 05, 2024

Commit Message Convention

Commit messages are crucial for maintaining a clear and organized project history. They serve as a communication tool among team members and help in understanding the evolution of a project. A well-crafted commit message can significantly enhance collaboration and project management. Here’s a comprehensive guide to writing effective commit messages:

Importance of a Convention

  • Consistency: Ensures all team members follow the same format, making it easier to read and understand commit logs. Consistent commit messages also facilitate the onboarding of new team members, as they can quickly grasp the project's history and changes. This uniformity is especially beneficial in large teams or open-source projects where many contributors are involved.
  • Efficiency: Streamlines the process of reviewing changes and identifying specific updates. Efficient commit messages save time during code reviews and help in quickly locating specific changes when debugging or enhancing features. They also aid in the process of merging branches, as clear messages can help resolve conflicts more effectively.
  • Tooling: Supports tools that automate release notes, changelogs, and other documentation. Properly formatted commit messages can be parsed by tools to generate detailed and accurate documentation, reducing manual effort and errors. This automation is crucial for maintaining up-to-date project documentation and ensuring that all changes are recorded accurately.

Structure of a Good Commit Message

  1. Subject Line: A concise summary of the change (50 characters or less).

    • Use the imperative mood (e.g., "Add", "Fix", "Update"). This style is a convention that aligns with the way commit messages are interpreted, as instructions to apply the change. It helps maintain a consistent tone across all messages.
    • Capitalize the first word to maintain a professional and uniform appearance. This small detail contributes to the overall readability and professionalism of the commit history.
    • Avoid ending with a period to keep the subject line clean and direct. This practice helps in maintaining a concise and to-the-point message.
  2. Body (optional): A detailed explanation of the change.

    • Describe the "what" and "why", not the "how". This helps others understand the purpose and context of the change without delving into implementation details. Providing this context is crucial for future reference, especially when revisiting old commits.
    • Wrap text at 72 characters to ensure readability across different tools and interfaces, which may have varying display widths. This wrapping ensures that the message is easily readable in various environments, such as terminal windows and web interfaces.
  3. Footer (optional): References to issues or breaking changes.

    • Include issue tracking numbers (e.g., "Resolves #456") to link the commit to specific tasks or bug reports, providing traceability. This linkage is invaluable for project management and tracking the progress of specific issues.
    • Mention any breaking changes to alert team members and users about modifications that may affect backward compatibility. Clearly documenting breaking changes is essential for maintaining the stability of the project and ensuring that all stakeholders are aware of significant updates.

Example

A well-structured commit message might look like this:

Add new feature: User can now view and manage their profile information.

- feat(profile): Add profile page to display user details.
- feat(profile): Implement profile editing functionality.
- feat(profile): Updated user interface to include profile section.

Conclusion

By adhering to this commit message convention, you can significantly enhance the readability and maintainability of your project. This structured approach not only improves collaboration but also ensures that your project's history is both informative and easy to navigate.