Making Better Git Commits - Semantic Commit Messages

Making Better Git Commits - Semantic Commit Messages

Today I will introduce you to a new way of writing commits. The semantic way. This way of writing commit messages improves the readability of your commits and also the meaning. If anyone looks at your git commit history, they should say, "Wow. That is the cleanest history I have ever seen", so let's take a step further for our goal and look at how exactly do your write such semantic commit messages.

Format: ():

Example: feat: add hat wobble ^--^ ^------------^ | | | +-> Summary in present tense. | +-------> Type: chore, docs, feat, fix, refactor, style, or test.

The above example is pretty classic. So semantic commit messages requires you, the committer to provide what is known as the type of commit, which in the above case involves feat or feature. These are all the types and their meaning:

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

As you can see from the example above, the summary or the subject or the text after the type is in present tense and has to be in present tense.

There is also a scope in the format above but there is no scope in the example. Why is that? The scope is optional in semantic commit messages. And when you don't add the scope you also omit the parenthesis around it.

Hope you found this post useful and productive and the next time someone looks at your commit history, they will say, "This is clean". And as always please react to this post and show me some love in the comments. Bye.