DEV Community

Cover image for How I write Commits like a pro

How I write Commits like a pro

phukon on April 08, 2024

Crafting effective commit messages is a hallmark of experienced developers. Embracing the Conventional Commits specification stands as a beacon for...
Collapse
 
theashraf profile image
Abdelrahman Ashraf

Thanks for sharing

I use this tool: github.com/streamich/git-cz, which is a CLI-guided tool to create awesome commit messages as well.

Collapse
 
pavlosisaris profile image
Paul Isaris

Very cool! Thanks for sharing!

Collapse
 
phukon profile image
phukon

this is so cool!

Collapse
 
donut87 profile image
Christian Baer

While the intent is good and for the most part this guideline is ok, I really do not like commit messages tell me what was done to the code. I can see that, when I look at the code. I want to know why this was changed. So please do not tell me, that you "changed the build process". I can see that. What I cannot see, by looking at the code is why we changed the build process. A message like "build process was taking 20 min, now takes 2" with some explanation in the body is way better. "Resolve issue with search feature" is also something, that I can see by git show --name-only pretty quickly. But what was the issue?
"Add a new rating component". Yes... I can see that you inserted a new file in folder 'rating-components' that pretty much gave it away already. What rating component? Is it replacing the old one? Is it country specific? Gender specific? (Don't flame me for this, that shit happens in real life)

Botton line: Having a what is better than nothing (aka 'Did stuff'), but having a why is even better.
Why > What > Nothing.

Collapse
 
shenoudafawzy profile image
Shenouda Fawzy

Good day Christian Baer, what if the product is +100K line of code, don't you think that 'What' is the most important thing in the commit message than 'why', otherwise whoever reading/reviewing might get lost.
For the 'Why' it's even more important, cause without it then it's pointless to do write whatever code is, but in context of the message commit, I prefer 'what' over than 'why' which could be described on the issue/ticket itself. And leave the commit message to 'what' is actually changed to achieve the task (that has the why)

Collapse
 
xtofl profile image
xtofl

Funny sidemark: we currently use a template that features both why and how:

feat(SF-123): Show SNP percentages

Why? because assay designers need to estimate how often
the base occurs in each designed primer

How? add 'frequencies' member to HTMLChar, and use it in
the dialog box.
Enter fullscreen mode Exit fullscreen mode
Collapse
 
the_olusolar profile image
Solar

In my opinion, I think one can use the what as description and then include the why in the body of the commit. that way, both are fulfilled.

Collapse
 
thesnowmanndev profile image
Kyle Martin

Why would one pull request encompass 100k+ lines of code exactly?

Collapse
 
borzoomv profile image
Borzoo Moazami

Nice post, thanks for sharing.
Also I think it worth to think about what we've done when trying to write the description.

For example there are times when we fix a bug by changing something in x.ts file.

Appropriate commit message would describe what issue we have resolved not what we changed in x.ts.

BTW thats my idea and I had better experience during reviewing more meaningful commits and don't know if it is a rule or something.

Thank you again.

Collapse
 
aneshodza profile image
anes

Also important to mention: Commit messages tend to be in the present and imperative.
E.g: Implement search feature.

Collapse
 
emamut profile image
Faber Andrés Vergara

Excellent post! The online tool that we use in the company where I work and has helped us with the commits is: commitlint.io/

Collapse
 
leew profile image
Wei Lee

Thanks for sharing! Would like to share this tool github.com/commitizen-tools/commit... which can help creating commit based on different rules (including convention commit)

Collapse
 
frankconnolly profile image
Frank Connolly

I tend to use feature branches so the scope part of the commit message is usually obvious based on that. Other than that I would steer towards this format as much as possible

Collapse
 
agesset profile image
Eag

Thanks for sharing ! I'll be sure to make my commit messages more precise.

Collapse
 
jeremysawesome profile image
Jeremiah Smith

I've been tossing a gitmoji at the beginning of commit messages these days. It offers similar categorization and makes it simple to see the intention of a commit at a glance.
gitmoji.dev/

Collapse
 
bunnyyum profile image
Tay

Thank you, this has been very helpful!

Collapse
 
yeasin2002 profile image
Md Kawsar Islam Yeasin

I would suggest to use commitlint if anyone want to preffer this kind of commit.

commitlint + husky is a perfect combinations.

Collapse
 
kevjetsky profile image
Kevin Glez

Aws!!

Collapse
 
alayande442 profile image
Alayande-442

Thank you boss🙏

Collapse
 
ahmadadibzad profile image
Ahmad Adibzad

Nice post, thanks for sharing.

Collapse
 
hamza_zahidul profile image
Hamza Zahidul Islam

Thanks brother 😀

Collapse
 
jitendrachoudhary profile image
Jitendra Choudhary

Nice article

Collapse
 
gadrawingz profile image
Gad Iradufasha

Nice post, Most developers don't care about the message provided in their commit messages!

Collapse
 
ppaanngggg profile image
ppaanngggg

Good example, thanks

Collapse
 
patriciaisaacs1997 profile image
PatriciaIsaacs1997

Thanks for the share!! I'm just getting started with Github and this will be something I start implementing from now on.

Collapse
 
madhusaini22 profile image
Madhu Saini

Thanks for sharing!!

Collapse
 
lordhazan profile image
lordhazan

Thank you

Collapse
 
aaroonasp profile image
Aaron Potter

Thanks. Great share.

Collapse
 
thannah profile image
Hannah Alcott

Good post!

Collapse
 
danhof profile image
Daniel Hofman

Fantastic insights on professional commit practices! If someone is looking for a tool to further enhance this process, consider checking out CommandGit app. It's designed to streamline Git operations.

Collapse
 
pedrosmasson profile image
Pedro Masson

Nice article, thanks for sharing your insights

Collapse
 
acudworth3 profile image
acudworth3

Has anyone found a good tool/extension to do this in vscode source control? I believe in this convention but it doesn’t play nicely with the small commit message window in vscode gui IMO. plus I’d rather it mostly be selectable from a menu of possible.

Collapse
 
dgg profile image
Daniel González García

marketplace.visualstudio.com/items...

We use this one in my team. Works nicely with our flow

Collapse
 
ayugup93 profile image
ayugup93

Some of the example commit message that I use are(Just for reference) :-
git commit "Initial Commit"
git commit "API Feature Completed"
git commit "Resolved comments for PR"
git commit "Merge developer PR's"

Collapse
 
uzeyir-yariz profile image
uzeyir-yariz

İ learn more English

Collapse
 
medikoo profile image
Mariusz Nowak

Following this for a while.

One thing that started to bother me is why "docs" and not "doc" (in other cases we use singular form, e.g. "test" not "tests", "style" not "styles" etc.)

Collapse
 
kumneger profile image
Kumneger0 • Edited

i use ai to write my commits using github.com/Nutlope/aicommits

Collapse
 
mortezakh12 profile image
Mortezakh12

A blackbox AI extension that automatically generates commits . its not bad.

Collapse
 
glyad profile image
David Kossoglyad (Hire me!)

Excuse me, I don't understand, has the mountain given birth to a mouse yet?

Collapse
 
draqun profile image
Damian Giebas

Let me just put it here: github.com/Everduin94/better-commits

Best regards.
Draqun