You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
prek install --hook-type commit-msg --hook-type pre-push
204
204
```
205
205
206
206
| Hook | Recommended Stage |
207
207
| ----------------- | ----------------- |
208
208
| commitizen | commit-msg |
209
209
| commitizen-branch | pre-push |
210
210
211
-
> **Note**: Replace `master` with the [latest tag](https://github.com/commitizen-tools/commitizen/tags) to avoid warnings. You can automatically update this with:
211
+
> [!Note]
212
+
> Replace `master` with the [latest tag](https://github.com/commitizen-tools/commitizen/tags) to avoid warnings. You can automatically update this with:
212
213
> ```sh
213
-
>pre-commit autoupdate
214
+
>prek autoupdate
214
215
>```
215
216
216
217
For more details about commit validation, see the [check command documentation](https://commitizen-tools.github.io/commitizen/commands/check/).
Copy file name to clipboardExpand all lines: docs/tutorials/auto_check.md
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,28 +2,29 @@
2
2
3
3
## About
4
4
5
-
To automatically check a commit message prior to committing, you can use a [Git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). This ensures that all commit messages follow your project's commitizen format before they are accepted into the repository.
5
+
To automatically check a commit message before committing, use a [Git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). This ensures all commit messages match your project's commitizen format before they are accepted into the repository.
6
6
7
-
When a commit message fails validation, Git will reject the commit and display an error message explaining what went wrong. You'll need to amend your commit message to follow the required format before the commit can proceed.
7
+
When a commit message fails validation, Git rejects the commit and displays an error explaining what went wrong. Update the message to the required format before trying again.
8
8
9
9
## How to
10
10
11
11
There are two common methods for installing the hooks:
12
12
13
13
### Method 1: Using pre-commit hook frameworks (Recommended)
14
14
15
-
Using pre-commit frameworks is the recommended approach as hook installation, updates, and execution are handled automatically.
16
-
These are two common pre-commit hooks:
15
+
Using pre-commit hook frameworks is the recommended approach because hook installation, updates, and execution are handled automatically.
16
+
Two common frameworks are:
17
17
-[prek](https://prek.j178.dev) (faster)
18
18
-[pre-commit](https://pre-commit.com/)
19
19
20
+
In the steps below, we'll use `prek`.
21
+
20
22
#### Step 1: Install prek
21
23
22
24
```sh
23
25
python -m pip install prek
24
26
```
25
27
26
-
27
28
#### Step 2: Create `.pre-commit-config.yaml`
28
29
29
30
Create a `.pre-commit-config.yaml` file in your project root directory with the following content:
@@ -49,12 +50,11 @@ Install the configuration into Git's hook system:
49
50
prek install --hook-type commit-msg
50
51
```
51
52
52
-
53
53
The hook is now active! Every time you create a commit, commitizen will automatically validate your commit message.
54
54
55
55
### Method 2: Manual Git hook installation
56
56
57
-
If you prefer not to use pre-commit, you can manually create a Git hook. This gives you full control over the hook script but requires manual maintenance.
57
+
If you prefer not to use a pre-commit framework, you can manually create a Git hook. This gives you full control over the hook script but requires manual maintenance.
0 commit comments