Convert Figma logo to code with AI

RomuloOliveira logocommit-messages-guide

A guide to understand the importance of commit messages and how to write them well

6,708
338
6,708
14

Top Related Projects

šŸ““ Lint commit messages

16,701

The commitizen command line utility. #BlackLivesMatter

95,657

Deliver web apps with confidence šŸš€

Git commit message: how to write a great git commit message and commit template for version control

A markdown version emoji cheat sheet

Quick Overview

The "commit-messages-guide" repository on GitHub is a comprehensive guide that provides best practices and recommendations for writing effective and meaningful commit messages. It covers various aspects of commit message writing, including structure, content, and style, to help developers improve their commit message quality and maintain a clean and informative commit history.

Pros

  • Comprehensive Guidance: The guide covers a wide range of topics related to commit message writing, providing a thorough and well-structured resource for developers.
  • Practical Examples: The guide includes numerous examples of good and bad commit messages, helping readers understand the concepts in a more tangible way.
  • Community Contributions: The project is open-source, allowing the community to contribute and improve the guide over time.
  • Language Support: The guide is available in multiple languages, making it accessible to a broader audience.

Cons

  • Opinionated Approach: The guide presents a specific set of recommendations, which may not align with the preferences or conventions of all development teams.
  • Lack of Customization: The guide does not provide much flexibility for users to adapt the recommendations to their specific project or organizational needs.
  • Potential Outdated Information: As the software development landscape evolves, some of the information in the guide may become outdated over time.
  • Limited Practical Exercises: While the guide includes examples, it lacks hands-on exercises or interactive elements to reinforce the concepts.

Getting Started

To get started with the "commit-messages-guide" repository, follow these steps:

  1. Clone the repository to your local machine:
git clone https://github.com/RomuloOliveira/commit-messages-guide.git
  1. Navigate to the project directory:
cd commit-messages-guide
  1. Open the guide in your preferred markdown viewer or editor. The main content is located in the README.md file.

  2. Explore the guide's sections, which cover topics such as:

    • Commit message structure
    • Commit message content
    • Commit message style
    • Examples of good and bad commit messages
    • Commit message tools and resources
  3. Apply the recommended practices to your own project's commit messages and observe the improvements in your commit history.

Competitor Comparisons

šŸ““ Lint commit messages

Pros of commitlint

  • Automated enforcement of commit message conventions
  • Integrates with popular development tools and CI/CD pipelines
  • Customizable rules and configurations to fit project needs

Cons of commitlint

  • Steeper learning curve for new contributors
  • May require additional setup and maintenance
  • Can be overly strict, potentially hindering quick commits or hotfixes

Code comparison

commit-messages-guide:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

commitlint:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore']],
  },
};

Summary

commit-messages-guide is a comprehensive guide for writing good commit messages, offering best practices and examples. It's more flexible and educational, suitable for teams that prefer guidelines over strict rules.

commitlint is a tool that enforces a specific commit message format. It's more rigid but ensures consistency across a project. It's ideal for teams that want to automate commit message validation and maintain a strict standard.

The choice between the two depends on the team's preferences, project requirements, and desired level of enforcement for commit message conventions.

16,701

The commitizen command line utility. #BlackLivesMatter

Pros of cz-cli

  • Interactive CLI tool that guides users through commit message creation
  • Enforces consistent commit message format across team members
  • Integrates with popular version control systems and CI/CD pipelines

Cons of cz-cli

  • Requires installation and setup, which may be overkill for smaller projects
  • Less flexibility in commit message structure compared to a guide-based approach
  • Learning curve for team members unfamiliar with the tool

Code Comparison

commit-messages-guide provides examples of good commit messages:

Fix bug where user can't signup

When a user tried to signup, a 500 error was returned.

Root cause: timeout connecting to Redis server

Fix: increase Redis timeout to 5 seconds

cz-cli generates commit messages through a series of prompts:

? Select the type of change that you're committing: (Use arrow keys)
āÆ feat:     A new feature
  fix:      A bug fix
  docs:     Documentation only changes
  style:    Changes that do not affect the meaning of the code
  refactor: A code change that neither fixes a bug nor adds a feature
  perf:     A code change that improves performance
  test:     Adding missing tests or correcting existing tests

commit-messages-guide offers a comprehensive guide on writing effective commit messages, focusing on best practices and examples. It's a static resource that developers can reference when crafting their commits.

cz-cli, on the other hand, is an interactive tool that streamlines the commit process by prompting users for specific information. It ensures consistency but may limit creativity in message composition.

Both approaches aim to improve commit message quality, but they cater to different preferences and project needs.

95,657

Deliver web apps with confidence šŸš€

Pros of Angular

  • Comprehensive framework for building web applications
  • Large community and extensive ecosystem of tools and libraries
  • Well-documented with detailed guides and API references

Cons of Angular

  • Steeper learning curve due to its complexity
  • Larger file size and potentially slower initial load times
  • More opinionated, which may limit flexibility in some cases

Code Comparison

Angular (TypeScript):

@Component({
  selector: 'app-root',
  template: '<h1>{{ title }}</h1>'
})
export class AppComponent {
  title = 'Hello, Angular!';
}

Commit Messages Guide (Markdown):

# Good commit messages
- Use the imperative mood in the subject line
- Capitalize the subject line
- Do not end the subject line with a period
- Limit the subject line to 50 characters
- Use the body to explain what and why vs. how

While Angular is a full-fledged web application framework, the Commit Messages Guide is a focused resource for writing better commit messages. Angular provides a complete solution for building complex web applications, including routing, state management, and component-based architecture. On the other hand, the Commit Messages Guide offers specific guidelines for improving version control practices, which can be applied to any project regardless of the technology stack.

Angular's repository contains the framework's source code, documentation, and related tools, making it significantly larger and more complex. The Commit Messages Guide repository is simpler, primarily consisting of markdown files with guidelines and examples for writing effective commit messages.

Git commit message: how to write a great git commit message and commit template for version control

Pros of git-commit-message

  • More comprehensive coverage of commit message topics, including advanced concepts like semantic versioning and commit types
  • Includes examples of commit message templates and tools for enforcing commit message standards
  • Provides guidance on commit message length and structure, with detailed explanations

Cons of git-commit-message

  • Less concise and more verbose, which may be overwhelming for beginners
  • Lacks a clear, step-by-step guide for writing commit messages
  • Some sections contain redundant information, potentially diluting the main points

Code Comparison

commit-messages-guide:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

git-commit-message:

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

Both repositories provide similar commit message structures, with git-commit-message offering a slightly more detailed format. The main difference lies in the presentation and depth of explanations surrounding these structures.

commit-messages-guide offers a more concise and beginner-friendly approach, focusing on essential guidelines and best practices. It provides clear examples and explanations without overwhelming the reader with excessive details.

git-commit-message, on the other hand, delves deeper into various aspects of commit messages, offering a more comprehensive resource for those seeking in-depth knowledge. It covers additional topics like semantic versioning and provides more extensive examples and tools for implementing commit message standards.

Ultimately, the choice between these repositories depends on the user's needs and experience level. Beginners may find commit-messages-guide more approachable, while advanced users might appreciate the depth of information in git-commit-message.

A markdown version emoji cheat sheet

Pros of emoji-cheat-sheet

  • Comprehensive list of emojis with their corresponding shortcodes
  • Regularly updated to include new emojis
  • Provides a quick reference for emoji usage in various platforms

Cons of emoji-cheat-sheet

  • Focuses solely on emojis, lacking guidance on commit message structure
  • May encourage overuse of emojis in commit messages
  • Doesn't provide context for when to use specific emojis in commits

Code comparison

commit-messages-guide:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

emoji-cheat-sheet:

:emoji_name:

Summary

commit-messages-guide provides a structured approach to writing effective commit messages, offering guidelines and best practices. It focuses on improving communication and project history through well-crafted commit messages.

emoji-cheat-sheet, on the other hand, is a comprehensive reference for emojis and their shortcodes. While it can be useful for adding visual elements to commit messages, it doesn't provide guidance on message structure or content.

The choice between these repositories depends on the user's needs. For those looking to improve their commit message practices, commit-messages-guide is more suitable. For users seeking a quick emoji reference, emoji-cheat-sheet is the better option. Ideally, both resources can be used complementarily to create informative and visually appealing commit messages.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Commit messages guide

Say Thanks!

A guide to understanding the importance of commit messages and how to write them well.

It may help you to learn what a commit is, why it is important to write good messages, best practices and some tips to plan and (re)write a good commit history.

Available languages

What is a "commit"?

In simple terms, a commit is a snapshot of your local files, written in your local repository. Contrary to what some people think, git doesn't store only the difference between the files, it stores a full version of all files. For files that didn't change from one commit to another, git stores just a link to the previous identical file that is already stored.

The image below shows how git stores data over time, in which each "Version" is a commit:

Why are commit messages important?

  • To speed up and streamline code reviews
  • To help in the understanding of a change
  • To explain "the whys" that cannot be described only with code
  • To help future maintainers figure out why and how changes were made, making troubleshooting and debugging easier

To maximize those outcomes, we can use some good practices and standards described in the next section.

Good practices

These are some practices collected from my experiences, internet articles, and other guides. If you have others (or disagree with some) feel free to open a Pull Request and contribute.

Use imperative form

# Good
Use InventoryBackendPool to retrieve inventory backend
# Bad
Used InventoryBackendPool to retrieve inventory backend

But why use the imperative form?

A commit message describes what the referenced change actually does, its effects, not what was done.

Capitalize the first letter

# Good
Add `use` method to Credit model
# Bad
add `use` method to Credit model

The reason that the first letter should be capitalized is to follow the grammar rule of using capital letters at the beginning of sentences.

The use of this practice may vary from person to person, team to team, or even from language to language. Capitalized or not, an important point is to stick to a single standard and follow it.

Try to communicate what the change does without having to look at the source code

# Good
Add `use` method to Credit model

# Bad
Add `use` method
# Good
Increase left padding between textbox and layout frame
# Bad
Adjust css

It is useful in many scenarios (e.g. multiple commits, several changes and refactors) to help reviewers understand what the committer was thinking.

Use the message body to explain "why", "for what", "how" and additional details

# Good
Fix method name of InventoryBackend child classes

Classes derived from InventoryBackend were not
respecting the base class interface.

It worked because the cart was calling the backend implementation
incorrectly.
# Good
Serialize and deserialize credits to json in Cart

Convert the Credit instances to dict for two main reasons:

  - Pickle relies on file path for classes and we do not want to break up
    everything if a refactor is needed
  - Dict and built-in types are pickleable by default
# Good
Add `use` method to Credit

Change from namedtuple to class because we need to
setup a new attribute (in_use_amount) with a new value

The subject and the body of the messages are separated by a blank line. Additional blank lines are considered as a part of the message body.

Characters like -, * and ` are elements that improve readability.

Avoid generic messages or messages without any context

# Bad
Fix this

Fix stuff

It should work now

Change stuff

Adjust css

Limit the number of characters

It's recommended to use a maximum of 50 characters for the subject and 72 for the body.

Keep language consistency

For project owners: Choose a language and write all commit messages using that language. Ideally, it should match the code comments, default translation locale (for localized projects), etc.

For contributors: Write your commit messages using the same language as the existing commit history.

# Good
ababab Add `use` method to Credit model
efefef Use InventoryBackendPool to retrieve inventory backend
bebebe Fix method name of InventoryBackend child classes
# Good (Portuguese example)
ababab Adiciona o mƃĀ©todo `use` ao model Credit
efefef Usa o InventoryBackendPool para recuperar o backend de estoque
bebebe Corrige nome de mƃĀ©todo na classe InventoryBackend
# Bad (mixes English and Portuguese)
ababab Usa o InventoryBackendPool para recuperar o backend de estoque
efefef Add `use` method to Credit model
cdcdcd Agora vai

Template

This is a template, written originally by Tim Pope, which appears in the Pro Git Book.

Summarize changes in around 50 characters or less

More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.

Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.

Further paragraphs come after blank lines.

 - Bullet points are okay, too

 - Typically a hyphen or asterisk is used for the bullet, preceded
   by a single space, with blank lines in between, but conventions
   vary here

If you use an issue tracker, put references to them at the bottom,
like this:

Resolves: #123
See also: #456, #789

Rebase vs. Merge

This section is a TL;DR of Atlassian's excellent tutorial, "Merging vs. Rebasing".

Rebase

TL;DR: Applies your branch commits, one by one, upon the base branch, generating a new tree.

Merge

TL;DR: Creates a new commit, called (appropriately) a merge commit, with the differences between the two branches.

Why do some people prefer to rebase over merge?

I particularly prefer to rebase over merge. The reasons include:

  • It generates a "clean" history, without unnecessary merge commits
  • What you see is what you get, i.e., in a code review all changes come from a specific and entitled commit, avoiding changes hidden in merge commits
  • More merges are resolved by the committer, and every merge change is in a commit with a proper message
    • It's unusual to dig in and review merge commits, so avoiding them ensures all changes have a commit where they belong

When to squash

"Squashing" is the process of taking a series of commits and condensing them into a single commit.

It's useful in several situations, e.g.:

  • Reducing commits with little or no context (typo corrections, formatting, forgotten stuff)
  • Joining separate changes that make more sense when applied together
  • Rewriting work in progress commits

When to avoid rebase or squash?

Avoid rebase and squash in public commits or in shared branches where multiple people work on. Rebase and squash rewrite history and overwrite existing commits, doing it on commits that are on shared branches (i.e., commits pushed to a remote repository or that comes from others branches) can cause confusion and people may lose their changes (both locally and remotely) because of divergent trees and conflicts.

Useful git commands

rebase -i

Use it to squash commits, edit messages, rewrite/delete/reorder commits, etc.

pick 002a7cc Improve description and update document title
pick 897f66d Add contributing section
pick e9549cf Add a section of Available languages
pick ec003aa Add "What is a commit" section"
pick bbe5361 Add source referencing as a point of help wanted
pick b71115e Add a section explaining the importance of commit messages
pick 669bf2b Add "Good practices" section
pick d8340d7 Add capitalization of first letter practice
pick 925f42b Add a practice to encourage good descriptions
pick be05171 Add a section showing good uses of message body
pick d115bb8 Add generic messages and column limit sections
pick 1693840 Add a section about language consistency
pick 80c5f47 Add commit message template
pick 8827962 Fix triple "m" typo
pick 9b81c72 Add "Rebase vs Merge" section

# Rebase 9e6dc75..9b81c72 onto 9e6dc75 (15 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into the previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

fixup

Use it to clean up commits easily and without needing a more complex rebase. This article has very good examples of how and when to do it.

cherry-pick

It is very useful to apply that commit you made on the wrong branch, without the need to code it again.

Example:

$ git cherry-pick 790ab21
[master 094d820] Fix English grammar in Contributing
 Date: Sun Feb 25 23:14:23 2018 -0300
 1 file changed, 1 insertion(+), 1 deletion(-)

add/checkout/reset [--patch | -p]

Let's say we have the following diff:

diff --git a/README.md b/README.md
index 7b45277..6b1993c 100644
--- a/README.md
+++ b/README.md
@@ -186,10 +186,13 @@ bebebe Corrige nome de mƃĀ©todo na classe InventoryBackend
 ``
 # Bad (mixes English and Portuguese)
 ababab Usa o InventoryBackendPool para recuperar o backend de estoque
-efefef Add `use` method to Credit model
 cdcdcd Agora vai
 ``

+### Template
+
+This is a template, [written originally by Tim Pope](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), which appears in the [_Pro Git Book_](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project).
+
 ## Contributing

 Any kind of help would be appreciated. Example of topics that you can help me with:
@@ -202,3 +205,4 @@ Any kind of help would be appreciated. Example of topics that you can help me wi

 - [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/)
 - [Pro Git Book - Commit guidelines](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines)
+- [A Note About Git Commit Messages](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)

We can use git add -p to add only the patches we want to, without the need to change the code that is already written. It's useful to split a big change into smaller commits or to reset/checkout specific changes.

Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]? s
Split into 2 hunks.

hunk 1

@@ -186,7 +186,6 @@
 ``
 # Bad (mixes English and Portuguese)
 ababab Usa o InventoryBackendPool para recuperar o backend de estoque
-efefef Add `use` method to Credit model
 cdcdcd Agora vai
 ``

Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?

hunk 2

@@ -190,6 +189,10 @@
 ``
 cdcdcd Agora vai
 ``

+### Template
+
+This is a template, [written originally by Tim Pope](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), which appears in the [_Pro Git Book_](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project).
+
 ## Contributing

 Any kind of help would be appreciated. Example of topics that you can help me with:
Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]?

hunk 3

@@ -202,3 +205,4 @@ Any kind of help would be appreciated. Example of topics that you can help me wi

 - [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/)
 - [Pro Git Book - Commit guidelines](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines)
+- [A Note About Git Commit Messages](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)

Other interesting stuff

Like it?

Say thanks!

Contributing

Any kind of help would be appreciated. Example of topics that you can help me with:

  • Grammar and spelling corrections
  • Translation to other languages
  • Improvement of source referencing
  • Incorrect or incomplete information

Inspirations, sources and further reading