Logo

dev-resources.site

for different kinds of informations.

# How to write good commit messages

Published at
12/13/2024
Categories
git
github
commit
devops
Author
chamal1120
Categories
4 categories in total
git
open
github
open
commit
open
devops
open
Author
10 person written this
chamal1120
open
# 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 in imperative mood if it is a simple commit (means a one liner).
  2. Have a title in imperative 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 mode Exit fullscreen mode

Detailed Commit:

Add caching mechanism to improve performance

Implemented a caching layer to reduce redundant database calls,
which improves page load times by approximately 30%.

Fixes #42.
Enter fullscreen mode Exit fullscreen mode

This is written following the Git 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 view

Pagination improves performance for blogs with a large number 
of posts. Closes #42.
Enter fullscreen mode Exit 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 module

Simplified the code by removing redundant checks and aligning
with the latest OAuth2 library changes.
Enter fullscreen mode Exit 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 page

This page includes basic details about the user and their recent
activity. Also adds lazy loading for the profile module.
Enter fullscreen mode Exit 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 mode Exit 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 mode Exit 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.

commit Article's
30 articles in total
Favicon
Why I Built commit-ai: A Story About Git Security and Team Safety
Favicon
使用 AI 自動生成 Git Commit 訊息
Favicon
# How to write good commit messages
Favicon
Conventional Git Commits With Best Practices.
Favicon
Understanding Git Rebase Merge: Chronological vs Logical Order and Commit History
Favicon
Improving Commit Message Quality in VSCode with Copilot
Favicon
TIL how to see the entire commit column on GitLab using JS
Favicon
Why Going Back in Git Doesn't Have to Be Scary
Favicon
🤖 Use AI to speed up writing commit messages (bonus: custom prompt for improved generation)
Favicon
How to commit
Favicon
Commits Semânticos: Organizando o Caos com Padrões de Mensagens
Favicon
Consequences of for-Git-ting to merge the master into feature branch!
Favicon
Git: Commit Messages
Favicon
Yazılım Projelerinde Düzen ve Verimlilik İçin: Conventional Commits Nedir?
Favicon
Good commit message V/S Bad commit message 🦾
Favicon
วิธี sign commit ด้วย GPG บน GitHub
Favicon
Git Together: Pro Tips for Commits and Branches
Favicon
Commit vs. Rollback: Database Transaction Essentials
Favicon
Sign Git Commits and Authenticate to GitHub with SSH Keys
Favicon
Developers Hate This One Weird Trick To Be Improve Their Craft
Favicon
Conventional Commits
Favicon
Cara memperbaiki commit git yang terlanjur commited
Favicon
Multiple SSH id
Favicon
💻 Semantic Commits
Favicon
Client side Git hooks 101
Favicon
How to write GIT commit messages
Favicon
The Power of Conventional Commits ✨✨
Favicon
What I've Learned About Git from Senior Colleagues (Part 2 - thoughful commit)
Favicon
GitHub Commits Color Scheme: Lets commit to commit.
Favicon
How do I make a Git commit in the past?

Featured ones: