A lightweight golang implementation of git commit-msg hook.
Zero dependency, almost. ( homedir
with only ONE file is the ONLY dependency, no indirect dependencies. )
English | 中文
Just put the executable binary into the hook directory of your project which using git as VCS.
Assuming the project root is /
, the hook directory should be /.git/hooks/
. Please make sure the binary is named as commit-msg
or commit-msg.exe
(win) , and the executable permission is granted.
If you can't find the hook directory, make sure the hidden directories are shown.
After installation, git will call it automatically to validate commit message, no manual calls are required.
You can download the latest pre-built binary from here . However, only win64 binaries are available.
For platforms other than win64, please setup the go environment and build it yourself.
Sorry for the poor instructions.
The configuration file can be placed in two places:
- global config:
$HOME/.commit-msg.json
- project config:
project/.git/hooks/.commit-msg.json
Both configuration files can be set with neither or both, or you can choose to have only one of them. The program will try to load the global configuration first, then the project configuration, and the items set in both profiles will be subject to the project configuration.
The default commit-message format:
<type>(<scope>): <subject> // empty line <body> // empty line <footer>
Example:
feat(model): some changes to model layer * change 1 * change 2 other notes BREAKING CHANGE: some change break the compatibility the way to migrate: ...
The following configuration items are supported.
lang
: prompt language. Currently only the built-inen
andzh
are supported, later on we will support adding custom language.scopeRequired
: if true,(<scope>)
will be required.scopes
: a list of strings, if not null or empty, thenscope
must take a value from the list. This setting takes effect only whenscope
is non-empty, and is independent ofscopeRequired
.types
anddenyTypes
: both are string lists; keywords from types lists will be added to the default keyword list; keywords from denyTypes will be removed (if any). If a keyword appears in both lists, denyTypes prevails, since the keyword list addtypes
first and removedenyTypes
later. The default type keyword list is:feat
: new featuresfix
: bug fixesdocs
: documentsstyle
: the style of the code, modifications that do not affect the running logicrefactor
: refactoring (logical changes neither new features nor to fix errors)perf
: performance-related changestest
: test related changeschore
: chores, maybe ancillary functions relatedbuild
: build process relatedci
: continuous integration relateddocker
: docker image building relatedrevert
andRevert
: the revert message generated by some tools is uppercase.
bodyRequired
: if true, message body must be contained. (not only message header)lineLimit
: length limit of every single line, in bytes.
If there are no configuration files, the program will use the following default configuration:
{ "lang": "en", "scopeRequired": false, "bodyRequired": false, "lineLimit": 80 }
The project was first inspired by validate-commit-msg . ( It has now been moved to conventional-changelog/commitlint )
For more information about conventionalcommits
, please see https://www.conventionalcommits.org/