Counting Duplicate Commit Messages
To support my point, I also checked one of the larger repos at work for duplicate commit messages. It was simple to do but I thought I’d share my script in case anyone else wants to use it on their own repos and offer constructive feedback to their own colleagues!
git log --oneline | cut -c 10- | sort | uniq -c | sort -n
This shows every commit message in the history of the project, with a count of how many times it appears – and it sorts them by that count (increasing, so that the most repeated messages appear immediately above your cursor when the command completes). Typically I do see quite a few “Merge branch master into ….” type messages and we also have some automation that produces some very similar messages – all that is fair enough. When I find the person who thinks that “Update [filename]” is an acceptable commit message though, I will be taking some time to ~point and laugh~ offer some constructive advice.
Also published on Medium.
Note that if you have a really busy repo, you may need to bump that cut command up to 12- as the hash will be longer.
[code]
git log –pretty=format:’%s’ | sort | uniq -c | sort -n
[/code]
Works a little more safely and reliably