Debian Codegraph @

docs/config/configuration_file.md

raw
1 # Configuration File
2
3 Commitizen uses configuration files to customize its behavior for your project. These files define settings such as which commit rules to use, version management preferences, changelog generation options, and more.
4
5 ## Creating a Configuration File
6
7 It is recommended to create a configuration file via our [`cz init`](../commands/init.md) command. This command will guide you through setting up your configuration file with the appropriate settings for your project.
8
9 ## File Location and Search Order
10
11 Configuration files are typically located in the root of your project directory. Commitizen searches for configuration files in the following order:
12
13 <!-- DEPENDENCY: commitizen/defaults.py CONFIG_FILES -->
14
15 1. `.cz.toml`
16 2. `cz.toml`
17 3. `.cz.json`
18 4. `cz.json`
19 5. `.cz.yaml`
20 6. `cz.yaml`
21 7. `pyproject.toml` (in the `[tool.commitizen]` section)
22
23 The first valid configuration file found will be used. If no configuration file is found, Commitizen will use its default settings.
24
25 !!! note
26 Commitizen supports explicitly specifying a configuration file using the `--config` option, which is useful when the configuration file is not located in the project root directory.
27 When `--config` is provided, Commitizen will only load configuration from the specified file and will not search for configuration files using the default search order described above. If the specified configuration file does not exist, Commitizen raises the `ConfigFileNotFound` error. If the specified configuration file exists but is empty, Commitizen raises the `ConfigFileIsEmpty` error.
28
29 ```bash
30 cz --config <PATH> <command>
31 ```
32
33 !!! tip
34 For Python projects, you can add your Commitizen configuration to `pyproject.toml` to keep all project configuration in one place.
35
36 !!! warning "Multiple Configuration Files"
37 If Commitizen detects more than one configuration file in your project directory (excluding `pyproject.toml`), it will display a warning message and identify which file is being used. To avoid confusion, ensure you have only one Commitizen configuration file in your project.
38
39 ## Supported Formats
40
41 Commitizen supports three configuration file formats:
42
43 - **TOML** (`.toml`) - Recommended for Python projects
44 - **JSON** (`.json`)
45 - **YAML** (`.yaml`)
46
47 All formats support the same configuration options. Choose the format that best fits your project's ecosystem.
48
49 ## Configuration Structure
50
51 === "TOML Format"
52
53 For TOML files, Commitizen settings are placed under the `[tool.commitizen]` section. If you're using a standalone `.cz.toml` or `cz.toml` file, you can use `[tool.commitizen]` or just `[commitizen]`.
54
55 **Example: `pyproject.toml`, `.cz.toml` or `cz.toml`**
56
57 ```toml title="pyproject.toml"
58 [tool.commitizen]
59 name = "cz_conventional_commits"
60 version = "0.1.0"
61 version_provider = "commitizen"
62 version_scheme = "pep440"
63 version_files = [
64 "src/__version__.py",
65 "pyproject.toml:version"
66 ]
67 tag_format = "$version"
68 update_changelog_on_bump = true
69 changelog_file = "CHANGELOG.md"
70 changelog_incremental = false
71 bump_message = "bump: version $current_version → $new_version"
72 gpg_sign = false
73 annotated_tag = false
74 major_version_zero = false
75 prerelease_offset = 0
76 retry_after_failure = false
77 allow_abort = false
78 message_length_limit = 0
79 allowed_prefixes = [
80 "Merge",
81 "Revert",
82 "Pull request",
83 "fixup!",
84 "squash!",
85 "amend!"
86 ]
87 breaking_change_exclamation_in_title = false
88 use_shortcuts = false
89 pre_bump_hooks = []
90 post_bump_hooks = []
91 encoding = "utf-8"
92
93 # Optional: Custom styling for prompts
94 style = [
95 ["qmark", "fg:#ff9d00 bold"],
96 ["question", "bold"],
97 ["answer", "fg:#ff9d00 bold"],
98 ["pointer", "fg:#ff9d00 bold"],
99 ["highlighted", "fg:#ff9d00 bold"],
100 ["selected", "fg:#cc5454"],
101 ["separator", "fg:#cc5454"],
102 ["instruction", ""],
103 ["text", ""],
104 ["disabled", "fg:#858585 italic"]
105 ]
106 ```
107
108 === "JSON Format"
109
110 For JSON files, Commitizen settings are placed under the `commitizen` key.
111
112 **Example: `.cz.json` or `cz.json`**
113
114 ```json title=".cz.json"
115 {
116 "commitizen": {
117 "name": "cz_conventional_commits",
118 "version": "0.1.0",
119 "version_provider": "commitizen",
120 "version_scheme": "pep440",
121 "version_files": [
122 "src/__version__.py",
123 "pyproject.toml:version"
124 ],
125 "tag_format": "$version",
126 "update_changelog_on_bump": true,
127 "changelog_file": "CHANGELOG.md",
128 "changelog_incremental": false,
129 "bump_message": "bump: version $current_version → $new_version",
130 "gpg_sign": false,
131 "annotated_tag": false,
132 "major_version_zero": false,
133 "prerelease_offset": 0,
134 "retry_after_failure": false,
135 "allow_abort": false,
136 "message_length_limit": 0,
137 "allowed_prefixes": [
138 "Merge",
139 "Revert",
140 "Pull request",
141 "fixup!",
142 "squash!",
143 "amend!"
144 ],
145 "breaking_change_exclamation_in_title": false,
146 "use_shortcuts": false,
147 "pre_bump_hooks": [],
148 "post_bump_hooks": [],
149 "encoding": "utf-8",
150 "style": [
151 ["qmark", "fg:#ff9d00 bold"],
152 ["question", "bold"],
153 ["answer", "fg:#ff9d00 bold"],
154 ["pointer", "fg:#ff9d00 bold"],
155 ["highlighted", "fg:#ff9d00 bold"],
156 ["selected", "fg:#cc5454"],
157 ["separator", "fg:#cc5454"],
158 ["instruction", ""],
159 ["text", ""],
160 ["disabled", "fg:#858585 italic"]
161 ]
162 }
163 }
164 ```
165
166 === "YAML Format"
167
168 For YAML files, Commitizen settings are placed under the `commitizen` key.
169
170 **Example: `.cz.yaml` or `cz.yaml`**
171
172 ```yaml title=".cz.yaml"
173 commitizen:
174 name: cz_conventional_commits
175 version: "0.1.0"
176 version_provider: commitizen
177 version_scheme: pep440
178 version_files:
179 - src/__version__.py
180 - pyproject.toml:version
181 tag_format: "$version"
182 update_changelog_on_bump: true
183 changelog_file: CHANGELOG.md
184 changelog_incremental: false
185 bump_message: "bump: version $current_version → $new_version"
186 gpg_sign: false
187 annotated_tag: false
188 major_version_zero: false
189 prerelease_offset: 0
190 retry_after_failure: false
191 allow_abort: false
192 message_length_limit: 0
193 allowed_prefixes:
194 - Merge
195 - Revert
196 - Pull request
197 - fixup!
198 - squash!
199 - amend!
200 breaking_change_exclamation_in_title: false
201 use_shortcuts: false
202 pre_bump_hooks: []
203 post_bump_hooks: []
204 encoding: utf-8
205 style:
206 - - qmark
207 - fg:#ff9d00 bold
208 - - question
209 - bold
210 - - answer
211 - fg:#ff9d00 bold
212 - - pointer
213 - fg:#ff9d00 bold
214 - - highlighted
215 - fg:#ff9d00 bold
216 - - selected
217 - fg:#cc5454
218 - - separator
219 - fg:#cc5454
220 - - instruction
221 - ""
222 - - text
223 - ""
224 - - disabled
225 - fg:#858585 italic
226 ```
227
228 ## Configuration Options
229
230 For a complete list of all available configuration options and their descriptions, see the [Configuration Settings](../config/option.md) documentation.
231
232 Key configuration categories include:
233
234 - **Commit Rules**: `name` - Select which commit convention to use
235 - **Version Management**: `version`, `version_provider`, `version_scheme`, `version_files`
236 - **Tagging**: `tag_format`, `legacy_tag_formats`, `ignored_tag_formats`, `gpg_sign`, `annotated_tag`
237 - **Changelog**: `changelog_file`, `changelog_format`, `changelog_incremental`, `update_changelog_on_bump`
238 - **Bumping**: `bump_message`, `major_version_zero`, `prerelease_offset`, `pre_bump_hooks`, `post_bump_hooks`
239 - **Commit Validation**: `allowed_prefixes`, `message_length_limit`, `allow_abort`, `retry_after_failure`
240 - **Customization**: `customize`, `style`, `use_shortcuts`, `template`, `extras`
241
242 ## Customization
243
244 For advanced customization, including creating custom commit rules, see the [Customization](../customization/config_file.md) documentation.
245
246 !!! note
247 The `customize` option is supported in TOML, JSON, and YAML configuration files. For Python projects, adding it to `pyproject.toml` keeps all project configuration in one place.