Skip to content

Commit c17833b

Browse files
committed
docs(check): rewrite command document
1 parent 4ade721 commit c17833b

File tree

2 files changed

+101
-42
lines changed

2 files changed

+101
-42
lines changed

docs/commands/check.md

Lines changed: 99 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,154 @@
1-
# Check
1+
This feature checks whether a string or a range of git commits follows the given committing rules. Comments in git messages will be ignored.
22

3-
## About
4-
5-
This feature checks whether the commit message follows the given committing rules. Comments in git messages will be ignored.
6-
7-
If you want to set up an automatic check before every git commit, please refer to
8-
[Automatically check message before commit](../tutorials/auto_check.md).
3+
To set up an automatic check before every git commit, please refer to [Automatically check message before commit](../tutorials/auto_check.md).
94

105
## Usage
116

127
![cz check --help](../images/cli_help/cz_check___help.svg)
138

14-
There are three mutually exclusive ways to use `cz check`:
9+
More specifically, there are three mutually exclusive ways to use `cz check`:
10+
11+
- Validate a range of git commit messages with `--rev-range`
12+
- Validate a given string with `--message` or by piping the message to it
13+
- Validate a commit message from a file with `--commit-msg-file`
14+
15+
### Use `cz check` to validate a commit message before committing
16+
17+
#### Option 1: use `--message` to check a given string:
18+
19+
```bash
20+
cz check --message <message_to_be_checked>
21+
```
22+
23+
#### Option 2: pipe the message to `cz check`:
24+
```bash
25+
echo <message_to_be_checked> | cz check
26+
```
27+
28+
#### Option 3: use `--commit-msg-file` to read the commit message from a file
29+
```bash
30+
cz check --commit-msg-file /path/to/file.txt
31+
```
1532

16-
- with `--rev-range` to check a range of pre-existing commits
17-
- with `--message` or by piping the message to it to check a given string
18-
- or with `--commit-msg-file` to read the commit message from a file
33+
## Command Line Options
1934

20-
### Git Rev Range
35+
### `--rev-range`
2136

22-
If you'd like to check a commit's message after it has already been created, then you can specify the range of commits to check with `--rev-range REV_RANGE`.
37+
Test if a given range of commits in the git log passes `cz check`.
2338

2439
```bash
25-
$ cz check --rev-range REV_RANGE
40+
cz check --rev-range REV_RANGE
2641
```
2742

28-
For example, if you'd like to check all commits on a branch, you can use `--rev-range master..HEAD`. Or, if you'd like to check all commits starting from when you first implemented commit message linting, you can use `--rev-range <first_commit_sha>..HEAD`.
43+
For more information on `REV_RANGE`, check the [git documentation](https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#_commit_ranges).
44+
45+
#### Use cases
46+
47+
1. Validate the latest 3 commit messages:
48+
```bash
49+
cz check --rev-range HEAD~3..HEAD
50+
# or
51+
cz check --rev-range HEAD~3..
52+
# or
53+
cz check --rev-range HEAD~~~..
54+
```
55+
56+
1. Validate all git commit messages on some branch up to HEAD:
57+
```bash
58+
cz check --rev-range <branch_name>..HEAD
59+
```
60+
61+
For example, to check all git commit messages on `main` branch up to HEAD:
62+
```bash
63+
cz check --rev-range main..HEAD
64+
```
65+
66+
or if your project still uses `master` branch:
67+
```bash
68+
cz check --rev-range master..HEAD
69+
```
70+
71+
!!! note "Default branch"
72+
Usually the default branch is `main` or `master`.
73+
You can check the default branch by running `cz check --use-default-range`.
2974

30-
You can also use `--use-default-range` to check all commits from the default branch up to HEAD. This is equivalent to using `--rev-range <default_branch>..HEAD`.
75+
1. Validate all git commit messages starting from when you first implemented commit message linting:
3176

32-
For more information on how git commit ranges work, you can check the [git documentation](https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#_commit_ranges).
77+
**(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.
3378
34-
### Commit Message
79+
```bash
80+
cz check --rev-range <first_commit_sha>..HEAD
81+
```
3582
36-
There are two ways you can provide your plain message and check it.
83+
### `--use-default-range`
3784
38-
#### Method 1: use `-m` or `--message`
85+
Equivalent to `--rev-range <default_branch>..HEAD`.
3986
4087
```bash
41-
$ cz check --message MESSAGE
88+
cz check --use-default-range
89+
# or
90+
cz check -d
4291
```
4392
44-
In this option, `MESSAGE` is the commit message to be checked.
93+
### `--message`
4594
46-
#### Method 2: use pipe to pipe it to `cz check`
95+
Test if a given string passes `cz check`.
4796
4897
```bash
49-
$ echo MESSAGE | cz check
98+
cz check --message <message_to_be_checked>
5099
```
51100
52-
In this option, `MESSAGE` is piped to `cz check` and will be checked.
101+
### `--commit-msg-file`
53102
54-
### Commit Message File
103+
Test if a given file contains a commit message that passes `cz check`.
55104
56105
```bash
57-
$ cz check --commit-msg-file COMMIT_MSG_FILE
106+
cz check --commit-msg-file <path_to_file_containing_message_to_be_checked>
58107
```
59108
60-
In this option, `COMMIT_MSG_FILE` is the path of the temporary file that contains the commit message.
61-
This argument can be useful when cooperating with git hooks. Please check [Automatically check message before commit](../tutorials/auto_check.md) for more information about how to use this argument with git hooks.
109+
This can be useful when cooperating with git hooks. Please check [Automatically check message before commit](../tutorials/auto_check.md) for more detailed examples.
62110
63-
### Allow Abort
111+
### `--allow-abort`
112+
113+
Example:
64114
65115
```bash
66-
cz check --message MESSAGE --allow-abort
116+
cz check --message <message_to_be_checked> --allow-abort
67117
```
68118
69119
Empty commit messages typically instruct Git to abort a commit, so you can pass `--allow-abort` to
70120
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.
71121
72-
### Allowed Prefixes
122+
### `--allowed-prefixes`
123+
124+
Skip validation for commit messages that start with the specified prefixes.
73125
74-
If the commit message starts with some specific prefixes, `cz check` returns `True` without checking the regex.
75126
By default, the following prefixes are allowed:
76127
77128
- `Merge`
78129
- `Revert`
79130
- `Pull request`
80131
- `fixup!`
81132
- `squash!`
133+
- `amend!`
82134
83135
```bash
84-
cz check --message MESSAGE --allowed-prefixes 'Merge' 'Revert' 'Custom Prefix'
136+
cz check --message <message_to_be_checked> --allowed-prefixes 'Merge' 'Revert' 'Custom Prefix'
85137
```
86138
87-
### Commit message length limit
139+
### `--message-length-limit`
140+
141+
Restrict the length of **the first line** of the commit message.
88142
89-
The argument `-l` (or `--message-length-limit`) followed by a positive number can limit the length of commit messages.
90-
For example, `cz check --message MESSAGE -l 3` would fail the check, since `MESSAGE` is more than 3 characters long.
91-
By default, the limit is set to 0, which means no limit on the length.
143+
```bash
144+
# The following passes
145+
cz check --message "docs(check): fix grammar issues" -l 80
146+
147+
# The following fails
148+
cz check --message "docs:very long long long long message with many words" -l 3
149+
```
92150
93-
**Note that the limit applies only to the first line of the message.**
151+
By default, the limit is set to `0`, which means no limit on the length.
94152
95-
Specifically, for `ConventionalCommitsCz` the length only counts from the type of change to the subject, while the body and the footer are not counted.
153+
!!! note
154+
Specifically, for `ConventionalCommitsCz` the length only counts from the type of change to the subject, while the body and the footer are not counted.

docs/config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ setup(
407407
[major-version-zero]: commands/bump.md#-major-version-zero
408408
[prerelease-offset]: commands/bump.md#prerelease_offset
409409
[retry_after_failure]: commands/commit.md#retry
410-
[allow_abort]: commands/check.md#allow-abort
410+
[allow_abort]: commands/check.md#-allow-abort
411411
[version-scheme]: commands/bump.md#version-schemes-version-scheme
412412
[pre_bump_hooks]: commands/bump.md#pre_bump_hooks
413413
[post_bump_hooks]: commands/bump.md#post_bump_hooks
414-
[allowed_prefixes]: commands/check.md#allowed-prefixes
414+
[allowed_prefixes]: commands/check.md#-allowed-prefixes
415415
[additional-features]: https://github.com/tmbo/questionary#additional-features
416416
[customization]: customization.md
417417
[shortcuts]: customization.md#shortcut-keys

0 commit comments

Comments
 (0)