Commit
A commit is a snapshot of a Git repository. Commits should be short, ideally representing an atomic change.
Commit message
A common convention for formatting commit messages is as follows:
<prefix>: <summary>
[additional-explanation]
A commit message should start with a concise <summary>
and can optionally
include a more detailed [additional-explanation]
after a blank line. Instead
of focusing on what was done, it’s more useful to explain why the changes
were made in the <summary>
.
To categorize commits a <prefix>
can be used. A good convention to use is
conventional commits. The
commitlint project
expands on this and adds more categories. Use the following prefixes for commit
message titles:
Prefix | Category |
---|---|
feat | New functionality |
fix | Reworking existing code to solve bugs |
refact | Refactoring code |
docs | Adding documentation |
test | Adding or fixing tests |
bump | Incrementing version numbers of dependencies |
It is important to not introduce to many prefix categories. This will defeat the purpose if categorizing commits.
Emoji’s
Do not use emoji’s in commit messages like the gitmojiproject tries to achieve. Emojis do not provide any benefit to the commit message. There are still a lot of tools that lack proper emoji support. It is also way more difficult to filter or search commit messages when they use emojis for categorizing commits.
Undo commits
It might be desired sometimes to undo changes made by one or multiple commits. Prefer reverting over resetting commits to preserve the Git history.
See also
- A Medium article that explains the most common commit prefixes.
- A GitHub gist about conventional commit messages.