Day 0: How to Write a good Commit Message?

Commit messages are important means of communication between team members and for the lifecycle of the teams and projects since they include the context on which they were created. By inspecting the project history we can find out why some decisions were made when they were made.

Let’s start a simple dare. Let’s post one important thing to consider when writing a commit message. Just one simple thing with an example after nominated by someone. You should nominate another one after posting yours.

Okay, I’m starting first with a super simple rule.


Capitalize the commit message.
Begin all subject lines with a capital letter.

ex:
:white_check_mark: correct
Update the example page

:x: incorrect
update the example page


I nominate @osusara. Keep in mind; just one simple thing with an example! :wink:

5 Likes

Limit the subject line to 50 characters.

This length ensures that they are readable. GitHub’s UI is fully aware of these conventions. It will warn you if you go past the 50 character limit and will truncate any subject line longer than 72 characters with an ellipsis.

ex:
:white_check_mark: correct
Bug fixed in the example page

:x: incorrect
Hi, everyone, I have good news for you. I just fixed the bug in the example page. blah blah blah

I nominate @Yohan . Keep in mind; just one simple thing with an example! :wink:

5 Likes

Do not end the subject line with a period

Trailing punctuation is unnecessary in subject lines. Also when when you’re trying to keep them to 50 chars or less, Space is more important.

ex:
:white_check_mark: correct
Remove unnecessary imports

:x: incorrect
Remove unnecessary imports.

I nominate @Gravewalker. Keep in mind; just one simple thing with an example! :wink:

4 Likes

Use imperative mood
Write commit messages in the imperative mood. The imperative mood is a grammatical mood that forms a command or request. When we write commit messages in this mood it perfectly matches up with the auto-generated commit messages by git itself.

ex:
:white_check_mark: correct
Fix bug in the example page

:x: incorrect
Fixed bug in the example page
Fixes bug in the example page

I nominate @anjisvj for the next tip.

4 Likes

Try to communicate what the change does without having to look at the source code
It is useful in many scenarios (e.g. multiple commits, several changes and refactors) to help reviewers understand what the committer was thinking.

ex:
:white_check_mark: correct
Add use method to Credit model

:x: incorrect
Add use method

I nominate @piumal1999. :wink:

4 Likes

Separate subject from body with a blank line

If the commit message has both subject and body. It is good to separate those two with a blank line. It is useful when checking the git log.

ex:
:white_check_mark: correct
Update the github link

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras blandit varius varius. Nunc vulputate ac urna ac rutrum. Etiam tincidunt et nunc eget pretium. Morbi sed tempus augue. Duis sollicitudin lectus ac aliquet varius.

:x: incorrect
Update the github link
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras blandit varius varius. Nunc vulputate ac urna ac rutrum. Etiam tincidunt et nunc eget pretium. Morbi sed tempus augue. Duis sollicitudin lectus ac aliquet varius.

I nominate @BhathiyaTK :grin:

4 Likes

Remove unnecessary punctuation marks

If the commit message has unnecessary punctuation marks, It’s better to remove them and just put the commit message with necessary parts. This will helps git to understand your commit message properly.

ex:
:white_check_mark: correct
Fix bug in the main page

:x: incorrect
Hi, all! I fixed the bug in the div with a class called "something" on the main page. I hope this will help...

I nominate @janithRS :yum: to continue.

4 Likes

Specify the type of commit:

For Example

  • feat: The new feature you’re adding to a particular application
  • fix: A bug fix
  • style: Feature and updates related to styling
  • refactor: Refactoring a specific section of the codebase
  • test: Everything related to testing
  • docs: Everything related to documentation
  • chore: Regular code maintenance.[ You can also use emojis to represent commit types]

I nominate @Bawantha_Rathnayaka :upside_down_face:

2 Likes