# How to write good commit messages
December 13, 2024

# How to write good commit messages

If you’re here, you’ve most likely already used git and may be wondering “Am I writing commit messages to a good standard?”.

If yes, then you must read this article before embarking on your next big project.


So what is a good commit message?

Well, actually there are multiple standards for git commit messages. But they all should,

  1. written in crucial Mood if this is a simple commit (meaning one line).
  2. Has title in crucial If this was a detailed submission.
  3. Write logically and solve a problem for each question.
  4. Explicitly mention the problem or task (if any).


Let’s look at an example

Simple submission:

Fix typo in README
Enter full screen mode

Exit full screen mode

Submit details:

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 full screen mode

Exit full screen mode

This is written below Git flow style commits standard.


So what are the other criteria?

Since there are many more, I won’t write them all here. The following standards are the ones you are most likely to use and encounter as a software developer. Some further references will be linked at the end of the article for those who are curious.


1. GitHub streaming commit:

Popular among open source projects on GitHub. Usually a reference to a related issue or pull request (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 full screen mode

Exit full screen mode


2. Regular submission:

Probably the most widely used standard. There is a type at the beginning, followed by a semicolon, then scope, description, body, and footer.


Commonly used types include,

  • Feat: A new feature.
  • Fix: Bug fixes.
  • docs: Documentation updated.
  • style: Code style changes (for example, formatting, no logic changes).
  • Refactoring: Refactoring code without changing behavior.
  • perf: performance improvements.
  • Test: Add or update tests.
  • Build: Changes to build tools or dependencies.
  • ci: Continuously integrate updates.
  • Chores: Miscellaneous tasks (e.g., updating dependencies).
  • Revert: Revert previous commits.


Scope (optional):

Affected portions of the codebase (e.g., auth, api, ui).


describe:

A brief summary of imperative mood changes.


Text – Detailed submission (optional):

Detailed description of the changes.


Footer – detailed submission (optional):

Breaking change (BREAKING CHANGE: …) or issue reference (fix #123).


2. Tim Pope’s Guidelines:

Git expert Tim Pope recommends:

  • Limit subject lines to 50 characters.
  • Capitalize the first word of the subject.
  • Don’t end the topic with a period.
  • Use the imperative mood.
  • Separate text with blank lines.
Refactor user authentication module

Simplified the code by removing redundant checks and aligning
with the latest OAuth2 library changes.
Enter full screen mode

Exit full screen mode


3. Angular Submission Guidelines:

The basis for regular submissions.
Added new specific formats with types, ranges, etc.

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 full screen mode

Exit full screen mode


4. Semantic submission message:

Focus on using keywords to make your commits machine-readable.
Often integrated with tools such as semantic publishing.
Similar to traditional submissions, but may include specific metadata.

feature(login): implement Google OAuth login
Enter full screen mode

Exit full screen mode


6. Subject prefix standards:

Use a prefix to indicate the type of change.
Less formal than a traditional submission.

[Bugfix] Resolve incorrect total calculation
[Enhancement] Improve search performance
Enter full screen mode

Exit full screen mode


for further reference


Thanks

Thank you very much for reading this far. Comments welcome. Point out if I’ve missed any details or expressed errors. Let’s learn together and grow into better developers.

2024-12-13 15:05:48

Leave a Reply

Your email address will not be published. Required fields are marked *