There’s an old adage (source unknown),
along the lines of “Write every commit message like the next
person who reads it is an axe-wielding maniac who knows where you
live”. If I was that maniac and I’m delving through
reams of your code trying to track down a bug and all I can
understand from your commit message is “updated some
codes”, look out, I’m coming after you!
The whole idea of commit messages is to explain
why you committed the code. Every time you make any change to code,
you’re doing it for a reason. Maybe something was broken.
Maybe the customer didn’t like the colour scheme. Maybe
you’re just tweaking the build configuration. Whatever it is,
there’s a reason for it and you need to leave this behind
you.
Why? Well there are a few different reasons and
they differ depending on the context. For example, using a
“blame” feature or other similar functionality which
exposes who changed what and hopefully, why. I can’t remember
what I was doing in the Web.config of this project 18 months ago or
why I was mucking around with app settings, but because I left a
decent commit message, it all becomes very simple:
It’s a similar thing for looking at changes
over time. Whether I want to see the entire history of a file, like
below, or I just want to see what the team accomplished yesterday,
having a descriptive paper trail of comments means it doesn’t
take much more than a casual glance to get an idea of what’s
going on.
And finally, commit messages are absolutely
invaluable when it comes to tracking down errors. For example,
getting to the bottom of why the build is breaking in your
continuous integration environment. Obviously my example is overtly
obvious, but the point is that bringing this information to the
surface can turn tricky problems into absolute no-brainers.
With this in mind, here are some anti-patterns of
good commit messages:
- Some
Stuff
- It
works!
- fix
someerrors
- fix
- Fixed a
little bug...
-
Updated
-
typo
- Revision
1024!!
Ok, I picked these all out of the Stack Overflow
question about What is the WORST commit message you have ever
authored but the thing is that none of them are that dissimilar to
many of the messages I’ve seen in the past. They tell you
absolutely nothing about what has actually happened in the code;
they’re junk messages.
One last thing about commit messages; subsequent
commit messages from the same author should never be identical. The
reason is simple: you’re only committing to source control
because something has changed since the previous version. Your code
is now in a different state to that previous version and if your
commit message is accurate and complete, it logically cannot be
identical. Besides, if it was identical (perhaps there’s a
legitimate edge-case there somewhere), the log is now a bit of a
mess to read as there’s no way to discern the difference
between the two commits.