How to write GIT commit messages
Committing your work to git is like... Showing all people what you have done. For me that's every time a great feeling. At most, because others will review my code and give me some feedback about it. But before pushing all my changes to the remote-repository, I need to commit them locally. At this point we need some text to describe, what we have done. Let me give you some insights on how to write your commit messages like a pro.
1 • Keep it consistent
If you commit, use the same syntax and don't mix those in a project. I'll give you some examples for different ones in the next steps. But keep that in mind.
If you're searching for a commit, because you need to review a particular change you've made, or somebody else is scrolling through your commits, it's easier to find. Imagine, you have a list of many different syntax-styles like:
1 > change products rest-api 2 > bug(database): change database-handling to avoid too many connections 3 > 🎨: button 4 > verify that users are able to submit the form correctly 5 > Anpassung an neue Systeme (message written in another language)
How and in what longer time would you find the commit you're looking for, if you need to adjust your eyes at every single commit line or more baldy switch between different languages? Wouldn't it be better, if every single commit follows the same syntax? Then you don't need to read the whole sentence to know, what this commit is about. Ok, this only applies, if you follow a specific convention (so line 1, 4 and 5 are not following a good one to quickly get to know what this commit is for...).
2 • Choose a convention
There are some conventions for Git commits out there:
Those two styles are very similar. But they although have one thing together: There are really easy to read. Especially if you use the Commit Messages with Scope you instantly know to which module / part of the app the commit belongs to.
3 • GitMoji
I heard of this some time ago, but didn't used it for a long time. I reviewed GitMoj and using it now for every single commit. It gives some dynamic to the boring texts you often don't want to read. But with them, it's much more easier to find the right things.
4 • Combining
If you use any of these advices, it's great! If you combine them all and use them for every commit you make: it's perfect! in the last months I have often thought about what the best commit message template looks like. And I found a really comfortable and suitable one which I want to share with you. It's a mixture of consistency, uses the convention of scoped conventional commits and ... 🥁 Emojis!
// template for short commits: <gitmoji>(<scope>): <message (short)> | <ISSUE-ID> ✨(blog-service): add count-post method | GITM-1233 // template for longer commits: <gitmoji>(<scope>): <subject (short)> <list of things I've done> | <ISSUE-ID(s)> 🐛(blog-service): change post-paging functionality - change backend-pagination-parameter calculation - adapt frontend to changed pagination-parameters - fix pagination-styling | GITM-1235 & GITM-1236
5 • Summary
This article gave you some insights into how I write my commit messages. Hopefully I was able to show you some advantages of thinking about how to commit. Maybe you want to adapt one of these commit styles (hopefully the GitMoj-Semantic-style...).
git commit -m "📝(blog): add post for better git-commit messages"