This feature checks whether a string or a range of git commits follows the given committing rules. Comments in git messages will be ignored.
To set up an automatic check before every git commit, please refer to Automatically check message before commit.
More specifically, there are three mutually exclusive ways to use cz check:
Test if a given range of commits in the git log passes cz check.
For more information on REV_RANGE, check the git documentation.
Validate the latest 3 commit messages:
Validate all git commit messages on some branch up to HEAD:
For example, to check all git commit messages on main branch up to HEAD:
or if your project still uses master branch:
Default branch
Usually the default branch is main or master. You can check the default branch by running cz check --use-default-range.
Validate all git commit messages starting from when you first implemented commit message linting:
(Why this is useful?) Let's say you decided to enforce commit message today. However, it is impractical to git rebase all your previous commits. --rev-range helps you skip commits before you first implemented commit message linting by using a specific commit hash.
Equivalent to --rev-range <default_branch>..HEAD.
Test if a given string passes cz check.
Test if a given file contains a commit message that passes cz check.
This can be useful when cooperating with git hooks. Please check Automatically check message before commit for more detailed examples.
Example:
Empty commit messages typically instruct Git to abort a commit, so you can pass --allow-abort to permit them. Since git commit accepts the --allow-empty-message flag (primarily for wrapper scripts), you may wish to disallow such commits in CI. --allow-abort may be used in conjunction with any of the other options.
Skip validation for commit messages that start with the specified prefixes.
If not set, commit messages starting with the following prefixes are ignored by cz check:
For example,
Restrict the length of the first line of the commit message.
By default, the limit is set to 0, which means no limit on the length.
Note
Specifically, for ConventionalCommitsCz the length only counts from the type of change to the subject, while the body and the footer are not counted.