how to write git commit message
Introduction
The git commit message is very important. You can use commit message to generate CHANGELOG
in your ci pipeline Or any you want to do something.
So, We can standardize standard commit message for you or your team.
Installation
We can help ourselves to write beautiful message through some tools.
1 | brew install commitizen pre-commit |
Specification
The template include three part, header
, body
and footer
.
Header: <type>(<scope>): <subject>
type list:
- feat: A new feature
- fix: A bug fix
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- 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
- build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
- ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
- chore: Other changes that don’t modify src or test files
- revert: Reverts a previous commit
Body: 72-character wrapped.
- The body is a detailed description of this submission, which can be multiple lines, and each line should not exceed 72
characters - Explain the items and reasons of the code changes, as well as the comparison with the previous behavior
Footer:
- Fill in the task number (if any)
- BREAKING CHANGE (can be ignored), record incompatible changes, start with BREAKING CHANGE:, followed by a description
of the change, the reason for the change, and the migration method.
Set commit message template
Create a file call .gitmessage.txt
in $HOME
directory
1 | # Header |
Set git config template location
1 | git config --global commit.template ~/.gitmessage.txt |
Using commitizen
Initialize commitizen
and pre-commit
to standardize commit message when git commit.
1 | cz init |
And then you should get two files .cz.yaml
and .pre-commit-config.yaml
.
- .cz.yaml
1 | commitizen: |
- .pre-commit-config.yaml
1 | repos: |
You can create a new tag via cz bump
or other commands.
1 | usage: cz [-h] [--debug] [-n NAME] |