DEV Community

Akash Shyam
Akash Shyam

Posted on

Level Up Your Commit Messages With These Tips!

At some point, we’ve all come across a commit message we don’t understand. Let’s rectify that commit by commit:

1. Specify the type of comment

  • feat: for feature addition
  • fix: for bug fixes
  • refactor: for changing the way a code block is written without changing the final result
  • style: for style changes(CSS/Sass etc)
  • test: anything and everything about testing
  • docs: documentation addition/updates
  • chore: code maintenance

Do not restrict yourself to these types, feel free to add more types of comments but be consistent across the code base.

2. Never assume another developer understands the original problem i.e. the reason for the commit

I recently started working on an existing codebase along with 3 developers. Me and another dev just started working on the codebase. On the second day, when I woke up to pull the latest code to my database I see this:

fix: bug inside the StudentList screen regarding the list
// … some irrelevant details about the new solution
Enter fullscreen mode Exit fullscreen mode

When I looked at it, I had no idea what the problem was. After about 15 minutes of chatting back and forth, I finally understood the original problem.

Just a single paragraph, that’s all I ask. One paragraph describing the problem containing 2–3 lines. It will help you too in the future, when you come back later trying to fix a bug.

3. Limit the subject line to 50 characters

50 characters is not a hard limit, just a rule of thumb. Keeping subject lines at this length ensures that they are readable, and forces the author to think for a moment about the most concise way to explain what’s going on.

Github will truncate commit messages over 72 characters

Checkout the remaining article here. I've saved the best for the last!

Top comments (4)

Collapse
 
akashshyam profile image
Akash Shyam

Don't forget to check the remaining article here . It contains 4 more tips!

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Hey this is a great tip, I suggest adding conventional commits as well conventionalcommits.org/en/v1.0.0/

Collapse
 
akashshyam profile image
Akash Shyam

I actually have including some portions from the conventional commits page.

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Oh nice, thanks