How to Write Good Commit Messages
And why it’s so important
Many developers learn Git on the job and they are probably not aware of the things that matter the most! In fact, most of you underestimate the role of commit messages and devote little time to writing a description of what you’ve done. Nonetheless, this is a minor problem that should be solved once and for all!
What Is a Commit Message?
git commit command saves our changes to a local repository after staging in Git. Before saving changes, you should tell Git which changes you want to save as you have probably made a bunch of edits. A great way to do it is by adding a commit message to identify your changes. Roughly said, the commit message is your comment about the what and why behind each change.
Why Are Commit Messages Important?
If your Git history is seen only by you, you can do whatever you want. Once multiple contributors work on big projects, this practice is somewhat ignorant and irresponsible on your part. The primary importance of the commit message is its usefulness for someone in the future. If you want to solve this problem and do not know how or what steps should be taken, or you realize the importance of the topic and want to put an end to that, then this article is written for you!
What Should a Good Commit Message Be?
Here, we highlight some general rules for writing a proper commit message. If you follow some of them, you will improve your workflow.
Writing a commit message should take some time
Some of you write a message in a hurry so as to do your daily duty and move on. Run the
git log command and see your commit messages in the past. Looking over these messages, you would probably say, “This is such nonsense!” You should contribute just a single minute to write an appropriate commit message.
A commit message should include what and why
Git commit messages must contain information about what you’ve done and why for each change. If a commit message doesn’t include that information, then what is the point of writing it at all?
Grouping changes in related commits
Breaking things apart and keeping them together in a logical manner is preferable. As your commits show the progression of your work, you can make a history that will help you in the future.
Using consistent terminology and markup
Setting a shared terminology is mandatory to avoid further inconvenience as well as to make it easier to search in the Git repository. A standard markup format is also preferable.
Steps to Writing a Proper Commit Message
git commit with the
-m option to write a commit message:
git commit -m “Subject” -m “Description”
-m option is the title and the next is the body. You can also check how you can change the commit message.
As you see, the commit message consists of the title and the body.
The title should be isolated from the body. It summarizes the changes you’ve made in a commit. It should start with a capital letter and be 50 or fewer characters without a punctuation mark at the end.
You should correctly finish the sentence like this: “This commit will…”
The body is a brief summary of the changes. If you just added some minor changes and your message could be conveyed through the title, then you can skip this part.
In general, the body should explain the what and the why for your changes — not the how. This section is used in cases where the changed parts are not so obvious for others.
“Great things are not done by impulse, but by a series of small things brought together.” — George Eliot
Little things always matter! If you want to become a skilled developer, you should pay attention to those minor things and make them your daily habit. Commit messages adequately render the information about why the change was made, and understanding them right can make development and collaboration more efficient. Realizing the essential role of the commit message should be taken into account in your everyday workflow.