Skip to content

Instantly share code, notes, and snippets.

@nabily4e-dev
Last active March 13, 2023 11:33
Show Gist options
  • Save nabily4e-dev/e3ffe13f256a6e2133754960ed1b828e to your computer and use it in GitHub Desktop.
Save nabily4e-dev/e3ffe13f256a6e2133754960ed1b828e to your computer and use it in GitHub Desktop.
## Conventional Commits 1.0.0
Summary:
The Conventional Commits specification is a convention for writing commit messages on top of commit messages. It provides a lightweight set of rules to make an explicit commit history that makes it easier to write automated tools. This convention is aligned with Semantic Versioning and describes the features, fixes, and breaking changes made in commit messages.
The commit message structure should be as follows:
cppCopy code
```
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
```
The commit message should contain the following elements:
1. **fix:** a commit of the type `fix` patches a bug in the codebase. This is equivalent to `PATCH` in Semantic Versioning.
2. **feat:** a commit of the type `feat` introduces a new feature to the codebase. This is equivalent to `MINOR` in Semantic Versioning.
3. **BREAKING CHANGE:** a commit that has a footer `BREAKING CHANGE:` or appends `!` after the type/scope introduces a breaking API change. This is equivalent to `MAJOR` in Semantic Versioning. A BREAKING CHANGE can be part of commits of any type.
4. Other types such as `build:`, `chore:`, `ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`, and others are allowed and recommended by [commitlint](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional) based on the [Angular convention](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines).
5. Other footers can be provided following a convention similar to git trailers.
Additional types are not mandated by the Conventional Commits specification and have no implicit effect in Semantic Versioning unless they include a BREAKING CHANGE. A scope may be provided to a commit’s type to provide additional contextual information.
Examples:
1. Commit message with description and breaking change footer:
vbnetCopy code
```
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
```
2. Commit message with `!` to draw attention to breaking change:
vbnetCopy code
```
feat!: send an email to the customer when a product is shipped
```
3. Commit message with scope and `!` to draw attention to breaking change:
vbnetCopy code
```
feat(api)!: send an email to the customer when a product is shipped
```
4. Commit message with both `!` and BREAKING CHANGE footer:
rustCopy code
```
chore!: drop support for Node 6
BREAKING CHANGE: use JavaScript features not available in Node 6.
```
5. Commit message with no body:
makefileCopy code
```
docs: correct spelling of CHANGELOG
```
6. Commit message with scope:
scssCopy code
```
feat(lang): add Polish language
```
7. Commit message with multi-paragraph body and multiple footers:
vbnetCopy code
```
fix: prevent racing of requests
Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.
Remove timeouts which were used to mitigate the racing issue but are
obsolete now.
Reviewed-by: Z
Refs: #123
```
The specifications cover the following points:
1. Commits must be prefixed with a type, which consists of a noun followed by an optional scope and a required colon and space.
2. The type "feat" must be used when a commit adds a new feature to the application or library.
3. The type "fix" must be used when a commit represents a bug fix for the application.
4. A scope may be provided after a type, and must consist of a noun describing a section of the codebase surrounded by parentheses.
5. A description must immediately follow the type/scope prefix and provide a short summary of the code changes.
6. A longer commit body may be provided after the short description to provide additional contextual information about the code changes.
7. A commit body is free-form and may consist of any number of newline-separated paragraphs.
8. One or more footers may be provided after the body, each consisting of a word token followed by a separator and a string value.
9. A footer's token must use "-" in place of whitespace characters, except for "BREAKING CHANGE" which may be used as a token.
10. A footer's value may contain spaces and newlines, and parsing must terminate when the next valid footer token/separator pair is observed.
11. Breaking changes must be indicated in the type/scope prefix of a commit, or as an entry in the footer.
12. If included as a footer, a breaking change must consist of the uppercase text "BREAKING CHANGE" followed by a colon, space, and description.
13. If included in the type/scope prefix, breaking changes must be indicated by a "!" immediately before the colon. If "!" is used, "BREAKING CHANGE:" may be omitted from the footer section, and the commit description must be used to describe the breaking change.
14. Types other than "feat" and "fix" may be used in commit messages.
15. The units of information that make up Conventional Commits must not be treated as case-sensitive by implementers, with the exception of "BREAKING CHANGE" which must be uppercase.
16. "BREAKING-CHANGE" is synonymous with "BREAKING CHANGE" when used as a token in a footer.
Using Conventional Commits can provide a number of benefits, including automatically generating CHANGELOGs, determining semantic version bumps, communicating changes to team members and stakeholders, triggering build and publish processes, and making it easier for people to contribute to projects by providing a more structured commit history.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment