Zach Posten - 2022 Mar 07
You writing "fixed" is hurting your whole team
If you haven't read Chris Beams' infamous article about writing git commit messages, you should! That and other similar posts are where I pull many of my thoughts on the topic from. XKCD also has a fun comic on this topic.
The Beams article makes a lot of fantastic points and you should absolutely read it if you haven't already. He lays out seven rules, and I would add two more:
In this post, instead of repeating what more articulate authors than I have already said, I'm going to talk about the motivations behind the aforementioned rules, explain my additions in more depth, and talk about the most common mistakes that I see developers make when writing commit messages.
The motivation behind each of the rules that involves the subject line can be summed up in a single word, brevity (also consistency, but I was trying to be brief). The goal is to communicate as much useful information as possible about what this commit does in the fewest number of characters.
One could perhaps restate those rules as:
Conventional commits, in their own words are:
I have found that this convention makes commits clearer, while also encouraging them to be atomic.
The first place that I came across this syntax was in the Angular repo, but a number of other well-known projects have also adopted the convention. For example:
One of the biggest reasons that I think Conventional Commits are so important is that they force you (if you're not lying to yourself your team in your commit message) to make each commit atomic.
Having "and", "also", or a comma in your commit message means that your commit is not atomic, because it does at least two separate things.
The solution here isn't to omit half of the message, but instead to separate that one commit into two or more individual commits, each with good commit messages of their own.
The subject should be used to explain in the fewest number of characters possible what you did, never why you did it. Why should always be put in the body of the commit.
If I want to know why you did something, I'm already invested in it and I'm going to read the entirety of your commit message. No one needs to know why you did something at a glance. They need to know what you did at a glance.
Also, by its very nature, why will usually be lengthier than what, and you're not limited by the number of characters you can use in the body of the commit.
Many developers simply never write more in a commit than fits in the subject. This is unfortunate because complex changes, or even simple changes that were tricky to make really deserve more explanation than that.
I estimate that one out of every four commits that I write has a body to explain something. So I am certain that you will also create the occasional feature that your teammates would benefit from you explaining further.
Ticket numbers are really useful to have in your commit structure, but putting them in every commit wastes your valuable 50 characters and gets super repetitive.
Similar to the why piece of the commit message, if I want to know what ticket number a particular commit was involved with, I have no problem taking a few moments to quickly find that information, rather than having that information thrown in my face over, and over, and over again.
Instead of including the ticket number in every commit, try only including it in the commit created when you merge your Pull Request (whether that be a merge commit or a squash commit). If you really must include the ticket number in every commit, try putting it in the body of the commit instead.
Looking at the above list of commits, how many of them can you tell what that commit did? How many of them can you even make a guess?
Overly brief commit messages fail the one and only task of a commit message - to tell you what the commit did!
Having something like
WIP commit makes sense as you're working. Committing early and often make sure you never lose progress you've made. But before you ever make a Pull Request for those commits, you should have gone back and cleaned them up. Often that means squashing several WIP commits together into a single meaningful commit.