DEV Community

Cover image for How to write Git commit messages like a Pro!

How to write Git commit messages like a Pro!

Ritik Banger on October 10, 2022

When a developer go back into time to look for something he has worked on six months ago, many times he does not understand why he made that partic...
Collapse
 
cappe987 profile image
Casper

... a one-liner commit message is preferable.

I disagree with this. You said it yourself, a commit should explain why a change was made. Be it due to a bug, or to prepare for a new feature, or anything else. The title (first line) should be as you say, short and concise about what the commit does. But the commit body should contain more detailed reasons why. Explain the original bug or give an example on how to use the new feature.

I'm not saying every commit needs this. Sometimes line is enough. But far from always.

Collapse
 
ritikbanger profile image
Ritik Banger

Thanks for the comment, I have updated the article adding your inputs and why I mentioned that one linear messages are preferable.

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

But, in reality, most pros write them like this:

Fixes stuff
Enter fullscreen mode Exit fullscreen mode

😜

Collapse
 
oanouman profile image
Martial Anouman • Edited

Quite true, even if we shouldn't 😂.
But we are working on it...

Collapse
 
ritikbanger profile image
Ritik Banger

That's why we are here to change the reality. Happy Committing Jon.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

but a one-liner commit message is preferable.

Absolutely not!

Whether adding fancy metadata to the commit summary is useful or adds clutter is arguable, but saying that adding a well-written commit description below should preferably be skipped is just a very dumb take.

Always always always add as much context as necessary. Whether this means you add one more sentence to clarify why the change was necessary, or add a full description of how a bug was identified, anything that can help another developer figure out why a change was made is valuable information.

Collapse
 
ritikbanger profile image
Ritik Banger

Thanks for the comment, I have updated the article adding your inputs.

Collapse
 
arcticllama profile image
ArcticLlama • Edited

This reminded me of Commit Logs From Last Night. It apparently got shut down and redirected. There is a version of it here or here (Twitter feed).

My favorite is when frustrated developers fight in the commit messages.

Collapse
 
ritikbanger profile image
Ritik Banger

Haha That's funny reading those commit messages.

Collapse
 
shubhamsigdar profile image
Shubham Sigdar

Thank you @ritikbanger...very helpful article

Collapse
 
ritikbanger profile image
Ritik Banger

Thank you @shubhamsigdar

Collapse
 
geazi_anc profile image
Geazi Anc

Well written!

Collapse
 
ritikbanger profile image
Ritik Banger

Thanks @geazi_anc

Collapse
 
mnish9 profile image
Mnish9

very helpful

Collapse
 
ritikbanger profile image
Ritik Banger

Thanks @mnish9

Collapse
 
rawasthi231 profile image
Raghvendra Awasthi

Thanks Ritik,
For providing such informative stuff.

Collapse
 
ritikbanger profile image
Ritik Banger

Thanks @rawasthi231