Git commit messages are like footprints left in the journey of software development, guiding both developers and collaborators through the evolution of a project. Yet, crafting commit messages that are both concise and expressive is often an overlooked art.
Enter ✨ the 50/72 rule ✨, a time-tested convention that offers a straightforward framework for writing the kind of commit messages that enhance understanding and foster consistency across your codebase.
In this post, you will learn how to write more clean and concise commit messages using this that rule.
Understanding the 50/72 Rule
The 50/72 rule is designed to help developers write better commit messages by setting limits on the length of the subject and body lines, making them more readable and structured. Here's how it works:
50-character subject line
: Begin your commit message with a subject line that does not exceed 50 characters. This brevity encourages you to capture the primary essence of what the commit changes.72-character body lines
: If your commit message includes a body, each line should not exceed 72 characters. This keeps the message accessible across different interfaces that may wrap text awkwardly if lines are too long.
Why is the 50/72 Rule Useful?
The 50/72 rule is not just an arbitrary guideline; it serves specific purposes that significantly improve the quality and utility of your commit history.
Clarity
The discipline of limiting the subject line to 50 characters ensures that you provide a succinct, at-a-glance summary of the changes. This makes it easier for collaborators to grasp the purpose of changes quickly, without delving into the specifics immediately.
Readability
By maintaining 72-character lines in the body, each message remains easy to read across various platforms, whether you're using the command line or a web-based tool. This uniformity prevents line breaks from disjointing the flow of information.
Consistency
Consistent formatting of commit messages helps maintain a uniform log, making it easier to trace the development history of a project. The familiarity brought about by consistency is invaluable when you need to navigate or reference past changes.
How to Implement the 50/72 Rule
Implementing the 50/72 rule is straightforward, whether you're using a GUI or the command line to commit changes.
Writing Well-Formatted Commit Messages
Consider the following template
[Subject]
Brief summary of changes (under 50 characters)
[what are the applied changes]
- Use bullet points for lists or key points
- This makes it easy to read and comprehend
[why are the changes apply]
Detailed explanation of the changes being made. Why these changes
are necessary, and any background necessary to understand them.
This can be wrapped at 72 characters.
Here is an example of what a well-crafted commit message will look like.
Fix login issue on mobile devices
- Updated viewport settings in index.html
- Modified responsive CSS classes
- Refactor CSS main class to update fonts
The login issue occurred due to incorrect viewport settings,
which were not optimized for mobile screen resolutions. Adjusted
the viewport meta tag and tweaked the CSS to ensure consistent
rendering across devices.
Here's what makes this message fit well within the 50/72 framework:
Concise Subject
: The subject line succinctly describes the overarching change in 50 characters or fewer.Detailed Body
: The body, although optional, provides detailed context, making use of bullet points for clarity and precision without exceeding the 72-character limit per line.
Multiline Messages on the Command Line
Developers who prefer using the command line can format their messages with multiple -m
switches, or simply use a text editor initiated by the git commit
command. Common editors like vi
or vim
open via command line allow for a natural input method while respecting the 50/72 formatting.
Additional Tips for IntelliJ IDEA
An effective commit message should not only state what change was made, but also why it was made. By explaining the rationale behind a change, you can eliminate ambiguity and reduce the need for future clarifications.
How can you add this commit template via AI on your IDE?
Personally, I use IntelliJ AI Assistant, and this is the template I use to generate the commit message after I worked on my project files
Avoid overly verbose descriptions or unnecessary details.
Start with a short sentence in imperative form with an emoji at the start,
no more than 50 characters long.
Then leave an empty line and add three bullet points to summarize key takeaways.
Then leave an empty line and continue with a more detailed explanation.
Write only two or three sentences at most for the detailed explanation,
explaining why those changes are applied.
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn • Twitter • GitHub or Medium
Conclusion
Commit messages may appear mundane at a glance, yet their potential to enhance a collaborative development process is profound. By adopting the 50/72 rule, you not only write messages that respect best practices but also create documentation that is rich and readable.
Whether you are working on a team project or solo, this discipline will pay dividends in clarity and consistency.