DEV Community

Cover image for Git commit message convention that you can follow!
Ishan Makadia
Ishan Makadia

Posted on

Git commit message convention that you can follow!

Motivation of this blog is to curate all information at one place and to make more people aware about standards followed by industry.

Let's get started.....

A typical git commit message will look like

<type>(<scope>): <subject>
Enter fullscreen mode Exit fullscreen mode

"type" must be one of the following mentioned below!

  • build: Build related changes (eg: npm related/ adding external dependencies)
  • chore: A code change that external user won't see (eg: change to .gitignore file or .prettierrc file)
  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation related changes
  • refactor: A code that neither fix bug nor adds a feature. (eg: You can use this when there is semantic changes like renaming a variable/ function name)
  • perf: A code that improves performance
  • style: A code that is related to styling
  • test: Adding new test or making changes to existing test

"scope" is optional

"subject"

  • use imperative, present tense (eg: use "add" instead of "added" or "adds")
  • don't use dot(.) at end
  • don't capitalize first letter

Refer this link for more practical examples of commit messages

References:

Latest comments (54)

Collapse
 
hiruthikj profile image
Hiruthik J

This tool makes doing this very simple: itnext.io/writing-better-commits-6...

Collapse
 
offendingcommit profile image
Jonathan Irvin

Commit formats are a lot like linting rules. Some can be very strict, some can be very freeform.

The lesson here is that no matter what format you use, people can still have terrible commit messages.

fix(stuff): updates is a valid conventional commit format, but a useless commit message.

While conventional commit formats can help with breaking up commits (doc commits should be separate from style commits), it's important to try to keep commits atomic and transactional.

Collapse
 
kansoldev profile image
Yahaya Oyinkansola

I have read this before from Conventional Git commits website, but you have broken it down better for me, thank you!

Collapse
 
andersbilllinden profile image
Anders Lindén

I want to add "revert".

Collapse
 
andersbilllinden profile image
Anders Lindén • Edited

I like most of this, but should not unit tests come along with the code (in the same commit)? I would also prefer "feature" over "feat".

Collapse
 
sinacs profile image
Sinacs

It's helpful to me, thank you for this!

Collapse
 
thisurathenuka profile image
Thisura Thenuka

If you are using Jet Brains IDEs for development, you can use the following plugin to create commit messages according to this convention easily. Check it out

plugins.jetbrains.com/plugin/9861-...

Collapse
 
srnascimento40 profile image
SrNascimento40

Nice article, i already used this, but i never read about

Collapse
 
pankajpatel profile image
Pankaj Patel

I think this convention is nice for open-source projects but requires a lot of discipline to keep the commits atomic.

On an enterprise level where there is a task tracking system, I prefer to follow standard of `TASK-ID: ...' as most of the git ui softwares can link the tickets in project management tool.

Both works great in general but sometimes I really like to dig deeper to see the reasoning behind a change.

Collapse
 
nemo011 profile image
Nemo

Thank you for the article.
A quick suggestion, you need to change this link https://github.com/eslint/eslint/commits/master to https://github.com/eslint/eslint/commits/main. Otherwise it's giving 404.

Collapse
 
jhelberg profile image
Joost Helberg

Thanks for sharing, didn't see it in a list for quite a while. As documentation should relate 1:1 to code, I don't think "docs" should be a type. What about a bug in the docs? What about business rules changing? Use-case changing and the commit is about implementing it? Docs should go as there should hardly be any code change without doc-change and vice versa. Also feature looks a lot better than feat.
Thanks again for sharing, it is an important subject.

Collapse
 
mrdulin profile image
official_dulin
Collapse
 
mikaleb_77 profile image
Mikaleb

Git-cz

Collapse
 
towbee98 profile image
Tobiloba

I have a question , IS it possible to have multiple types in a single commit message

Collapse
 
andersbilllinden profile image
Anders Lindén

That should make the commits composite instead of atomic, which we maybe want to avoid.

Collapse
 
lakshayasood profile image
Lakshaya Sood

its a good practice to have atomic commits. Commit as small as a change can be labeled. Later you can git squash them in one big commit having release tag or feature tag

Collapse
 
andersbilllinden profile image
Anders Lindén • Edited

Yes, a good way of forcing better commits to only allow one scope.

Collapse
 
andy3520 profile image
andy3520

what about type: WIP for Work in progress. Do anyone use it like me?