Debian Codegraph @

docs/commands/commit.md

raw
1 ## Usage
2
3 ![cz commit --help](../images/cli_help/cz_commit___help.svg)
4
5 ## Overview
6
7 ![Using Commitizen cli](../images/cli_interactive/commit.gif)
8
9 The `commit` command provides an interactive way to create structured commits. Use either:
10
11 - `cz commit`
12 - `cz c` (shortcut)
13
14 By default, Commitizen uses conventional commits, but you can customize the commit rules to match your project's needs. See the [customization guide](../customization/config_file.md) for details.
15
16 ## Basic Usage
17
18 ### Interactive Commit Creation
19
20 Simply run `cz commit` in your terminal to start the interactive commit creation process. The command will guide you through creating a properly formatted commit message according to your configured rules.
21
22 ### Writing Messages to File
23
24 You can save the generated commit message to a file using:
25 ```sh
26 cz commit --write-message-to-file COMMIT_MSG_FILE
27 ```
28
29 This can be combined with `--dry-run` to only write the message without creating a commit. This is particularly useful for [automatically preparing commit messages](../tutorials/auto_prepare_commit_message.md).
30
31 ## Advanced Features
32
33 ### Git Command Options
34
35 You can pass any git commit options using the `--` syntax:
36 ```sh
37 cz commit <commitizen-args> -- <git-cli-args>
38
39 # Examples:
40 cz c --dry-run -- -a -S # Stage all changes and sign the commit
41 cz c -a -- -n # Stage all changes and skip the pre-commit and commit-msg hooks
42 ```
43
44 !!! warning
45 The `--signoff` option (or `-s`) is now recommended being used with the new syntax: `cz commit -- -s`. The old syntax `cz commit --signoff` is deprecated and will be removed in v5.
46
47 ### Retry
48
49 - Use `cz commit --retry` to reuse the last commit message after a failed commit attempt
50 - Set `retry_after_failure: true` in your configuration to automatically retry
51 - Use `cz commit --no-retry` to force a new commit message prompt
52
53 ### Message Length Control
54
55 Control the length of your commit messages using the `-l` or `--message-length-limit` option:
56 ```sh
57 cz commit -l 72 # Limits message length to 72 characters
58 ```
59
60 !!! note
61 The length limit only applies to the first line of the commit message. For conventional commits, this means the limit applies from the type of change through the subject. The body and footer are not counted.
62
63 ## Technical Notes
64
65 For platform compatibility, the `commit` command disables ANSI escaping in its output. This means pre-commit hooks coloring will be deactivated as discussed in [commitizen-tools/commitizen#417](https://github.com/commitizen-tools/commitizen/issues/417).