Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for # How to write good commit messages
Chamal Randika
Chamal Randika

Posted on

     

# How to write good commit messages

If you are here, chances are you have already used git and probably thinking "Am I writing my commit messages in a good standard?".

If yes, then you must read this before you go and do your next big project.

So what is a good commit message?

Well, there's actually multiple standards when it comes to git commit messages. But they all should,

  1. Be written inimperative mood if it is a simple commit (means a one liner).
  2. Have a title inimperative mood if it is a detailed commit.
  3. Write logically, each addressing a single concern.
  4. Reference issues or tasks explicitly (if there is any).

Let's look at an example

Simple Commit:

Fix typo in README
Enter fullscreen modeExit fullscreen mode

Detailed Commit:

Add caching mechanism to improve performanceImplemented a caching layer to reduce redundant database calls,which improves page load times by approximately 30%.Fixes #42.
Enter fullscreen modeExit fullscreen mode

This is written following theGit flow style commits standard.

So what are the other standards then?

Since there's many, I won't be writing all of them here. Below standards will be the ones you'll most probably should be using and encounter as a software developer. Some further references will be linked at the end of the article for curious people.

1. GitHub Flow-Style Commits:

Popular for open-source projects in GitHub. Often references related issues or pull requests (e.g., "Closes #123").

Add pagination to the blog list viewPagination improves performance for blogs with a large number of posts. Closes #42.
Enter fullscreen modeExit fullscreen mode

2. Conventional commits:

Probably the most widely used standard. Have a type at the beginning followed by a semi-colon and then a scope, description, body and a footer.

The commonly used types are,

  • feat: A new feature.
  • fix: A bug fix.
  • docs: Documentation updates.
  • style: Code style changes (e.g., formatting, no logic changes).
  • refactor: Code restructuring without changing behavior.
  • perf: Performance improvements.
  • test: Adding or updating tests.
  • build: Changes to build tools or dependencies.
  • ci: Continuous integration updates.
  • chore: Miscellaneous tasks (e.g., updating dependencies).
  • revert: Reverts a previous commit.

Scope (Optional):

The part of the codebase affected (e.g., auth, api, ui).

Description:

A short summary of the change in the imperative mood.

Body - for detailed commits(optional):

Detailed explanation of the change.

Footer - for detailed commits(optional):

Breaking changes (BREAKING CHANGE: ...) or issue references (Fixes #123).

2. Tim Pope's Guidelines:

Tim Pope, a Git expert, suggests:

  • Limit subject line to 50 characters.
  • Capitalize the first word of the subject.
  • Do not end the subject with a period.
  • Use the imperative mood.
  • Separate the body with a blank line.
Refactor user authentication moduleSimplified the code by removing redundant checks and aligningwith the latest OAuth2 library changes.
Enter fullscreen modeExit fullscreen mode

3. Angular Commit Guidelines:

The foundation for Conventional Commits.
Adds a specific format with types, scopes, and more.

feat(user): add user profile pageThis page includes basic details about the user and their recentactivity. Also adds lazy loading for the profile module.
Enter fullscreen modeExit fullscreen mode

4. Semantic Commit Messages:

Focuses on using keywords to make commits machine-readable.
Often integrated with tools like semantic-release.
Similar to Conventional Commits but may include specific metadata.

feature(login): implement Google OAuth login
Enter fullscreen modeExit fullscreen mode

6. Subject-Prefix Standards:

Uses a prefix to indicate the change type.
Less formal than Conventional Commits.

[Bugfix] Resolve incorrect total calculation[Enhancement] Improve search performance
Enter fullscreen modeExit fullscreen mode

For further references

Thank You

Load of thanks for reading up to here. comments are welcome. Point out if I have missed any details or stated anything erroneously. Let's learn together and grow to become better developers.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
achiranadeeshan profile image
Achira Nadeeshan
  • Joined

A simple and helpful guide.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Hello, Welcome to my DEV blog! 👋I love using linux for pretty much everything.
  • Location
    Colombo, Sri Lanka
  • Education
    UG @ SLTC, Sri Lanka
  • Pronouns
    He/him
  • Joined

More fromChamal Randika

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp