Debian Codegraph @

docs/tutorials/auto_prepare_commit_message.md

raw
1 # Automatically prepare message before commit
2
3 ## About
4
5 It can be desirable to use Commitizen for all types of commits (i.e. regular, merge,
6 squash) so that the complete git history adheres to the commit message convention
7 without ever having to call `cz commit`.
8
9 To automatically prepare a commit message prior to committing, you can
10 use a [prepare-commit-msg Git hook][prepare-commit-msg-docs]:
11
12 > This hook is invoked by git-commit right after preparing the
13 > default log message, and before the editor is started.
14
15 To automatically perform arbitrary cleanup steps after a successful commit you can use a
16 [post-commit Git hook][post-commit-docs]:
17
18 > This hook is invoked by git-commit. It takes no parameters, and is invoked after a
19 > commit is made.
20
21 A combination of these two hooks allows for enforcing the usage of Commitizen so that
22 whenever a commit is about to be created, Commitizen is used for creating the commit
23 message. Running `git commit` or `git commit -m "..."` for example, would trigger
24 Commitizen and use the generated commit message for the commit.
25
26 ## Installation
27
28 Copy the hooks from [here](https://github.com/commitizen-tools/commitizen/tree/master/hooks) into the `.git/hooks` folder and make them
29 executable by running the following commands from the root of your Git repository:
30
31 ```bash
32 wget -O .git/hooks/prepare-commit-msg https://raw.githubusercontent.com/commitizen-tools/commitizen/master/hooks/prepare-commit-msg.py
33 chmod +x .git/hooks/prepare-commit-msg
34 wget -O .git/hooks/post-commit https://raw.githubusercontent.com/commitizen-tools/commitizen/master/hooks/post-commit.py
35 chmod +x .git/hooks/post-commit
36 ```
37
38 ## Features
39
40 - Commits can be created using both `cz commit` and the regular `git commit`
41 - The hooks automatically create a backup of the commit message that can be reused if
42 the commit failed
43 - The commit message backup can also be used via `cz commit --retry`
44
45 [post-commit-docs]: https://git-scm.com/docs/githooks#_post_commit
46 [prepare-commit-msg-docs]: https://git-scm.com/docs/githooks#_prepare_commit_msg