loading...

How to write a good commit message

Chrissie on July 30, 2020

A commit message is a short description of the changes you've made to a file added before committing the changes. Good commit messages are importa... [Read Full]
pic
Editor guide
 

Short and clear, thank you for this article!
I tend to use emojis for the type - it shows the type of the commit at first glance, e.g.:

โž• :heavy_plus_sign: when adding a file or implementing a feature
๐Ÿ”จ :hammer: when fixing a bug or issue
๐Ÿ’š :green_heart: when improving code or comments
โšก :zap: when improving performance
๐Ÿ“œ :scroll: when updating docs or readme
๐Ÿ”‘ :key: when dealing with security
๐Ÿ” :repeat: when updating dependencies or data
โœ… :white_check_mark: when a new release was built
๐Ÿ‘• :shirt: when refactoring or removing linter warnings
โŒ :x: when removing code or files

... and looks awesome in the commit history:

 

Thanks for your tip!

Here is the web for other Git emoji ideas: gitmoji.carloscuesta.me/

For me, it looks too much to remember,

so I just use some emojis to keep it simple:

๐ŸŽ‰ :tada: initial commit ๐ŸŽ‰

๐Ÿš€ :rocket: [Add] when implementing a new feature

๐Ÿ”จ :hammer: [Fix] when fixing a bug or issue

๐ŸŽจ :art: [Refactor] when refactor/improving code

๐Ÿšง :construction: [WIP]

๐Ÿ“ :pencil: [Minor] Some small updates

 

It is too much to remember. I use github.com/carloscuesta/gitmoji-cli so that I don't have to remember which emoji is used for which type. It's a git commit hook, so I just do git commit, and it interactively helps me pick the appropriate emoji, write my commit message, and then drops it into my editor to make changes as needed.

If you must use an additional tool to remember your emoji meaning, I bet other too are lost for the interpretation of the emoji, once the wow effect has passed, I think words are much easier and quicker to understand :)

I almost always use both: emoji for recognizing the commit type at first glance and text for a clear and unambiguous description ๐Ÿ‘๐Ÿป

yes but even for the commit type, I find a word more meaningful than an emoji (and new people on the project / people reading commits without being part of the project) don't need to learn what emoji corresponds to what :).

You make using emojis sound like rocket science ๐Ÿ˜… we're talking about little pictures with clear content. A hammer is for fixing something, a scroll is for something documentation related. There really isn't much to learn ๐Ÿคทโ€โ™‚๏ธ

 

My pleasure ๐Ÿ˜Š
This is also a nice interpretation, in the end it's a matter of taste, I think.

 

I hate when people do stuff like this. It just looks confusing in the git log. Just use unicode emojis instead, they work everywhere.

BTW my favourite emojis for commit messages: ๐ŸŽ†๐ŸŽŠ๐ŸŽ‰๐Ÿ˜–๐Ÿ’ข๐Ÿ˜… (I usually put them at the end of the commit message though)

 

Thank you for this valuable addition. Most of the terminals / bash / consoles support way more than unicode emojis nowadays. So that shouldn't be a problem for most of us. Here is, what my git log looks like:

Unicode emojis are standardized though, while the :: notation is not.

 

I never thought to use emojis for that LOL. THIS'LL HELP ME A LOT. ๐Ÿคฉ

 

Glad I could help ๐Ÿ˜Š

 

Wow, it looks so awesome.
Tnx for sharing your tips :)

 

My pleasure ๐Ÿ˜Š

 

I've seen emojis being used in some projects but they always seemed intimidating to me, I'll have to look more into how to use them

 

It needs a little time to getting used to it, but then you don't want to be without it anymore, I promise ๐Ÿ˜‚

 

I ALWAYS forget that emojis are valid in all kinds of spaces now. I often use them in debug console messages to make it visual and easy to search, but using them in this git commit message format is super handy. Thanks for the recommendation!

 

You're very welcome, I'm glad it's useful for you ๐Ÿ˜Š

 

That's pretty awesome and fun way to write commit message!

 

Exactly what I experienced ๐Ÿ‘๐Ÿป

 

I think it would be better to write a complete post about the way you are using Emojis!
Keep it up ;)

 

Thank you for this suggestion and the encouragement - I'll draft this to my list of post ideas ๐Ÿ‘๐Ÿป

Nice to hear that you found my suggestion cool.
I'm waiting for your amazing post.

Keep Moving Forward ใƒ„

Code with ๐Ÿ’›

๐Ÿ…‘๐Ÿ…๐Ÿ…๐Ÿ…™๐Ÿ…˜

 

I LOVE THIS. I might even print it out and stick on my wall. Thankyou!

 

You're welcome ๐Ÿ˜Š

 
 

Thank You ๐Ÿ˜Š

 
 

I'm using git alias to create a beautiful commit message with emoji and my commit message structure looks like this.

[emoji] <type>(scope): <message>

e.g.

๐Ÿž FIX(pages): security issue fix on pages table

Here is my .gitconfig

# Git Commit, Add all and Push โ€” in one step.
cap = "!f() { git commit -m \"$@\"; }; f"
# NEW.
new = "!f() { git cap \"๐Ÿ“ฆ NEW($1): $2\"; }; f"
# IMPROVE.
imp = "!f() { git cap \"๐Ÿ‘Œ IMPROVE($1): $2\"; }; f"
# UPDATE.
up = "!f() { git cap \"โœ๐Ÿป UPDATE($1): $2\"; }; f"
# FIX.
fix = "!f() { git cap \"๐Ÿž FIX($1): $2\"; }; f"
# RELEASE.
rlz = "!f() { git cap \"๐Ÿš€ RELEASE($1): $2\"; }; f"
# DOC.
doc = "!f() { git cap \"๐Ÿ“– DOC($1): $2\"; }; f"
# TEST.
tst = "!f() { git cap \"๐Ÿค– TEST($1): $2\"; }; f"
# BREAKING CHANGE.
brk = "!f() { git cap \"โ€ผ๏ธ BREAKING CHANGES($1): $2\"; }; f"
# REMOVE
remove = "!f() { git cap \"๐Ÿ—‘ REMOVE($1): $2\"; }; f"
# REFACTOR
ref = "!f() { git cap \"โ™ป๏ธ REFACTOR($1): $2\"; }; f"
# INITIAL COMMIT
int = "!f() { git cap \"๐ŸŽ‰ INITIAL COMMIT($1): $2\"; }; f"
 

probably a good place to share some things about this:

Here is the "conventional commit" pattern, which is super useful to be able to automatically extract information from your commits, such as for a ChangeLog.
conventionalcommits.org/en/v1.0.0/

This post has been around for a long time, and it's great!
chris.beams.io/posts/git-commit/

This tool helps you write conventional commits with emoji!!! It's super cool
github.com/vivaxy/gacp?ts=4

 

You can share your git commit conventions in the team via e.g.:

add this into your "~/.gitconfig"-file

[commit]
  template = ~/.gitmessage

example: github.com/voku/dotfiles/blob/mast...

 

We store a file in the root of each project: .gitmessage

Then in the project's Contributing section in the Readme, we have:

Before contributing to this project, configure the commit template while in the project root:

git config commit.template .gitmessage

The contents of the gitmessage is:
jira/issue-####: Title of issue
Description of changes.

We then squash all commits on merge and enforce rebasing.

This makes for a very clean commit log like:

jira/issue-2: Do that
These are more changes.

jira/issue-1: Do this
These are the changes.

 

How do you enforce rebasing?

It's a setting in GitLab per project.

Settings > General > Merge Requests.
Under Merge method, select "Fast-forward merge".

Description is: "No merge commits are created. Fast-forward merges only. When conflicts arise the user is given the option to rebase."

 

Here's the super-concise commit message template that I've been using for years now (I've lost track of which blog post or comment I first picked it up from). I find it to be a helpful reminder, without inundating me with a wall of text every time I go to commit:

# If applied, this commit will...

# Why is this change being made?

# Provide links to any relevant tickets, URLs or other resources
 

Nice article, and also I would like to add my opinion:

  • do not care of "title", the commit related ticket should have it.
  • the commit body should be 2-3 line only, if longer, then you supposed to split the ticket into smaller tasks (SOLID).
  • do not include emoji, markdown or anything, just simple text. Do not forget, not everyone has the same stack and could make pain to read whatever you did
  • Include related ticket or tickets

Example
MYPROJ-420 Updated vendor libraries (lodash, robot, d3) for xyz page.

 

I wish my commits were that good, I did adopt this style a while back, also tried the gitmoji style for a while but, then I reverted back to simple - Add, Create, Remove, Delete titles. ๐Ÿ˜†

Might try this style of commits again, I really like how they look and the organization of them just feels better to me, also seems better for filtering with the colon as a separator. ๐Ÿ”ฅ

 

This is just one way to do it if you have no problem understanding your commits with the way you've been using then continue using that as long as it's clear and people won't have any trouble understanding the message.

 

This is pretty much how I've been doing commit messages for the past couple years, since adopting conventional commits and using standard version.

The only difference is my format is like this:
[type]([scope]): [Subject].

and then the optional body, which generally only gets filled out if it's a very large commit (usually a no-no) or is filled in automatically by github on squash & merge of a PR, or if there's a breaking change.

So for example:
feat(Foo): Adds the ability to bar.

fix(Bar): Bar should not prevent Foo.

BREAKING CHANGE: Bar now requires Baz.

Standard Version ingests these commits and automatically compiles a changelog, which we use as part of our deploy process. Result is an automagic changelog created on each production deploy that definitively captures all changes since the last deploy. It's glorious... and simple once you put the pieces in place.

 

The benefit of the scope being included is it will group all items by scope, alphabetically, in the changelog, and prefix each of the bulletpoints with that scope value so they're easy to spot.

 

We're always using a reference to our bug tracker system:

#{ticket no.} - {ticket title}

And we added a plugin to our bugtracker to "suggest" the correct commit message, which you can copy&paste into terminal or whatever git GUI in use ;)

 

My favorite is the top utility within procps-ng. The commit messages are phrased so that each and every line of text (even the subject and even the last line of every paragraph) has the exact same width. No cheating with double spaces.

Another "favorite" of mine is ImageMagick. Many of their commit messages are a bare "...".

 

You can make your repository commitizen-friendly by using the following tool. github.com/commitizen/cz-cli

You can also read more about commitizen here. conventionalcommits.org/en/v1.0.0/

Great article @chrissie

 

It's nice to add that this is just one convention of committing; check gnu.org/prep/standards/html_node/S... for an alternate widely used(especially in GNU projects) commit style. I normally default to that. Here's an example from some guix patch:

gnu: xorg-server: Fix CVE-2020-14347 via graft.

* gnu/packages/patches/xorg-server-CVE-2020-14347.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/xorg.scm (xorg-server/fixed): New variable.
(xorg-server)[replacement]: New field.
(xorg-server-wayland): Use package/inherit.
 

Just my personal opinion, but I really hate having external references to things like issue trackers in the git history. They only work when viewed on a single platform but break at best or link to different information at worst when viewed from a different platform.

 

Thanks for this article!

We're using Bluejava's git commit guide, it's clear and self-explanatory :)

The main difference with your guidelines is that it replace "refactor/chore" with "maint" (as in maintainability).

 

IMPERATIVE MOOD โ€ข IMPERATIVE MOOD โ€ข IMPERATIVE MOOD

i agree with what you say. i have discovered ;) that D^V * 1/Cq * T/P = L; where D is how much description there needs to be, V is how verbose the author is C is the amount of lines of clear readable documented code, Y is the amount of time which the developer has been coding in that language, P is the affinity of penguins on a scale of 0 => 1 and L is the length of the commit message needed.

en.wikipedia.org/wiki/Imperative_mood
git-scm.com/book/en/v2/Distributed...

basically if it doesn't fit on my 60 x 50 char buffer window its prolly not all going to be read. lol

 

Honestly, commit messages are something I have by and large ignored in my development workflow (as a mostly solo Salesforce developer), but I can absolutely see the value in this. Hopefully shifting into a role at a consultancy soon, and I really think this will be a big assist.

 

In my current company we use this method:

JiraTaskID - JiraTitle - Some description

It will result in something like:

1123 - Update dependencies for the users screen - Update package.json & yarn.lock.

Then we do a squash/rebase and it gives a really good looking tree :D

 

good one.

To enforce commit messages had written a script long back ( and a blog )
Validate the commit message, this will make sure we have the habit.
medium.com/@harisharavindan/server...

 

I use gitmoji.carloscuesta.me/

And I switch the footer and body, putting this issue system at higher importance.

 

Too much info', maybe? Personally, I dispense with the 'Type' stuff and infer that through branching, instead.

 

Good article I will be levelling up my boring git commit messages from now on :)

 

You study at Udacity too eh. I thought I recognized that post :)

 

In my project we send the commits like this

[Platform] [Ticket nr] [Subject] [Description]
or
[FE] JIRA-736 SignUp - Implement password regex

 

Hahaha. Thanks Chrissie

 

Thank a lot!
That's exactly what I need these days!

 
 

Thank you, short and very clear.

 

This is so helpful - I'm terrible with commit messages and have not made it a priority to figure out a consistent method on what to write. Appreciate this sort of formula you have created!

 

I didn't create it myself by the way, but you're welcome ๐Ÿ˜€

 

Thanks, helpfull

 

You're welcome :)

 

Great! I always wanted to improve my commit messages but didn't know what I should do but now you gave me a pattern/standard to follow.
Thank you

 

Our branches include the ticket nr. A githook then adds the ticket nr to every commit.

 

Not sure why it didnt work out-of-the-box for me :(
screenshot

 

How to see emojis on terminal on windows???

 

Small, deliverable changes. I'll commit single, completed and tested methods as part of a feature build. As long as it works and can be delivered.

 

I also use that, I avoid writing a body at all cost but I just wanted to put it out there just so people can know that it's an option ๐Ÿ˜€

 

I didnt know commit has a body. Thanks for sharing.

 

And if this not work you can use the random commit message generator.
Enjoy.

paulospx.github.io/some_if_stateme...

Code of Conduct Report abuse