Yevgeny Gorbachev | July 18th, 2017
Time is money. Time is expensive. Time to market is twice as expensive. Time of a high-skilled developer is as much expensive as you could imagine. That’s why a good commit message matters.
If you have been involved in a lot of different projects and worked with tons of source code bases during your career, you probably might read commit messages that are a total mess.
Here is a log fragment from the real code base:
What the changes were about? Why they were formatted so badly without keeping one style regardless the same code base? Who knows? It was a long time ago in a galaxy far, far away…
Then let’s compare them with the recent commits to the Spring framework on Github:
Which would you rather read? Which ones are concise and consistent?
A well-crafted commit message is the best way to communicate context about a change to other teammates. A source diff will tell what changed, but only the commit message can tell you why.
Peter Hutterer pointed it out:
There’s no strict definition of the ideal commit, but in the company we try to follow the known best practices. Some of them I have written below.
In accordance with Peter Hutterer, a good commit message should answer the three questions:
These three questions establish the context for the actual code changes, put reviewers and others into the frame of mind to look at the diff and check if the approach chosen was correct.
In general, a good commit should contain exactly one logical change. A logical change includes adding a new feature, fixing a specific bug, a code refactoring, etc. Don’t mix different changes from different areas within one commit, omit massive code changes in one commit as much as you can. It’s better to split them into several observable commits in accordance with the provided functionality. It will help reviewers a lot to understand the changes.
Chris Beams summarized the best practices of the great commit messages into the seven rules:
Keep in mind: This has all been said before.
For example:
The rules look quite simple but bring a lot. They put everybody on the same page, allow to keep the product’s consistency, properly track the changes, restore the rationale easily, without asking the author. Ironically, that author could be yourself several months earlier. But it doesn’t matter how long ago the changes have been done, and does the changes’ owner still work in the company in the same project.
Summarizing all the above, use the best practices, take care of your changes. Never forget, you are not alone, so a good commit message really matters.
Happy coding!