DEV Community

Better Commit Messages

Fernando B 🚀 on September 25, 2019

Better Commit Messages Going through my TL saw the below tweet, I felt attacked a bit. As a one man army on most of my projects, I alway...
Collapse
 
gabrieltoma profile image
Gabriel Toma

"Quick Fix" FTW!

Collapse
 
rokkoo profile image
Alfonso

"Fixed quick fix" =D

Collapse
 
kurtz1993 profile image
Luis Hernández

Fixed quick fix fix :V!

Collapse
 
amandaiaria profile image
Amanda Iaria

I didn't realize you could even make a template. Maybe now I won't forget to add some more content.

Collapse
 
thefern profile image
Fernando B 🚀

I didn't either, is incredibly crazy how configurable git is. 😁

Collapse
 
igormelo profile image
Igor Melo

It is actually pretty useful.
Now I use it all the time

Collapse
 
sonicoder profile image
Gábor Soós

What worked for us and I see it in many Github repositories is the Angular commit convention.

docs(changelog): update changelog to beta.5
fix(release): need to depend on latest rxjs and zone.js

The version in our package.json gets copied to the one we publish, and users need the latest of these.

You can read about it in the Angular contribution section or in the conventional commit description

Collapse
 
amartinno1 profile image
Alex Nostadt

In general I make small commits which solve one issue / task and aim not to mix up code refactoring with the actual task. In most cases a one liner is totally enough then. I also add the ticket number to get background information if necessary. In case it's a bug fix for a regression I add the commit hash that introduced it.
The one liner, ticket number and commit itself is fine for me. Yet this requires to set proper messages and a good maintained ticket.
Thus, tbh I sometimes catch myself not doing it. If possible I fix things by using the interactive rebasing then.

Bottom line, as of now I am not using templates.

Collapse
 
thefern profile image
Fernando B 🚀

Yeah everyone got a different workflow. You can add a one liner template to remind you too. 😉

Collapse
 
rynaro profile image
Henrique A. Lavezzo

git commit -m 'changes' 😂

Collapse
 
gervg profile image
Gervin Guevarra

This is pretty cool!
But I'd still prefer doing one line commit messages.

I try hard to make my code speak for itself. But whenever I really need to explain the whys, I put it in the ticket discussion or in the pull request.

Collapse
 
thefern profile image
Fernando B 🚀

Code speaks to you and only you. Even then after a few months maybe not even you lol.

Do you know if discussions are pulled once PR is merged?

Collapse
 
rafi993 profile image
Rafi

You could follow 50/72 format in your commit messages

stackoverflow.com/questions/229001...

Collapse
 
rafi993 profile image
Rafi

If you really want to you could use emoji's gitmoji.carloscuesta.me/

Collapse
 
thefern profile image
Fernando B 🚀

Thanks for the tip!

Collapse
 
sinewalker profile image
Mike Lockhart

I think templates per project can be a good idea, to make sure everyone meets the project guidelines, and to be a prompt for better messages. Otherwise if to in a hurry to get a patch out, then you'll make a crummy, no value message like 'fixed the fob'

I generally make commits that follow the guidelines from GitHub with one line, 50 char subject summary, then a blank line and more verbose summary, wrapped at 72 chars, with link to ticketing system or GitHub/GitLab issue for the full explanation. This plays well with editor tools like Magit (Emacs) or GitLense (Code), or git blame, which show just the first line in summaries or logs, but can expand our pop up the full commit message.

Collapse
 
davidmm1707 profile image
David MM👨🏻‍💻

"X fixed"
"Forgot to remove prints"
"Forgot to remove the last print"

Collapse
 
anwar_nairi profile image
Anwar

Very clever way to enforce convention on those meaningless commits messages! Great for people like me who use git blame viewer (I use GitLens on VSCode).

Collapse
 
bogy0 profile image
Bálint Lendvai

We use one line commit messages on conventional commit style, then we create detailed PRs with detailed problem and solution sections. The structure of the PT is defined in guthubs or template.

Collapse
 
thefern profile image
Fernando B 🚀

Yeah a very high percentage of repos don't implement templates unfortunately.