"and" as anti-pattern in git commit subject
2023-11-20 08:00:27 +0100 +0100
I try to avoid the word “and” in git commit subject messages. If I find myself typing “and” in the subject, I usually stop what I’m doing and rethink the scope of the commit.
For example, if I am working on fixing a bug involving a race condition in a class method, and while working on it, I realize that the class could better support unit testing with a light refactor, I might write a commit subject that reads:
Fix race condition in SomeClass#method and lightly refactor
But now I’ve signaled that there are two related but different concerns to review. Code review is much easier when the change is small in scope and self-contained.
When I find myself tempted to write “and”, that’s a signal that I should instead create a separate commit for this:
- Fix race condition in SomeClass#method
- lightly refactor
Better yet, I could re-order these, and clarify what “lightly refactor” is about:
- Refactor SomeClass to support unit testing
- Fix race condition in SomeClass#method
… that way, the refactor doesn’t get de-prioritized, but is a precondition to the bug fix.
And, following this git commit message template, I’d also prefix the subject with a component
:
- SomeClass: Refactor to support unit testing
- SomeClass: Fix race condition in #method
What other words in commit subjects are anti-patterns or signals that the scope of the commit should be narrower?