Debian Codegraph @

docs/commands/changelog.md

raw
1 ## About
2
3 Generates a changelog following the committing rules established.
4
5 When changelog generation is triggered by `cz bump --allow-no-commit` (with `--changelog` or `update_changelog_on_bump = true`), Commitizen still creates a release entry even when no commits are found in the selected revision range.
6
7 !!! tip
8 To create the changelog automatically on bump, add the setting [update_changelog_on_bump](../config/bump.md#update_changelog_on_bump)
9
10 ```toml
11 [tool.commitizen]
12 update_changelog_on_bump = true
13 ```
14
15 ## Usage
16
17 ![cz changelog --help](../images/cli_help/cz_changelog___help.svg)
18
19 ## Examples
20
21 ```bash
22 # Generate full changelog
23 cz changelog
24
25 # Or use the alias
26 cz ch
27
28 # Get the changelog for the given version
29 cz changelog 0.3.0 --dry-run
30
31 # Get the changelog for the given version range
32 cz changelog 0.3.0..0.4.0 --dry-run
33 ```
34
35 ## Constraints
36
37 Changelog generation is constrained only to **markdown** files.
38
39 ## Description
40
41 These are the variables used by the changelog generator.
42
43 ```md
44 # <version> (<date>)
45
46 ## <change_type>
47
48 - **<scope>**: <message>
49 ```
50
51 Creates a full block like above per version found in the tags, and a list of the commits found.
52 The `change_type` and `scope` are optional and don't need to be provided,
53 but if your regex parses them, they will be rendered.
54
55 The format followed by the changelog is from [keep a changelog][keepachangelog]
56 and the following variables are expected:
57
58 | Variable | Description | Source |
59 | ------------- | ---------------------------------------------------------------------------------------------- | -------------- |
60 | `version` | Version number which should follow [semver][semver] | `tags` |
61 | `date` | Date when the tag was created | `tags` |
62 | `change_type` | The group where the commit belongs to, this is optional. Example: fix | `commit regex` |
63 | `message` | Information extracted from the commit message | `commit regex` |
64 | `scope` | Contextual information. Should be parsed using the regex from the message, it will be **bold** | `commit regex` |
65 | `breaking` | Whether it is a breaking change or not | `commit regex` |
66
67 !!! note
68 `message` is the only variable required to be parsed by the regex.
69
70 ## Command line options
71
72 ### `--extras`
73
74 Provide your own changelog extra variables by using the `extras` settings or the `--extra/-e` parameter.
75
76 ```bash
77 cz changelog --extra key=value -e short="quoted value"
78 ```
79
80 ### `--file-name`
81
82 Specify the name of the output file. Note that changelog generation only works with Markdown files.
83
84 ```bash
85 cz changelog --file-name="CHANGES.md"
86 ```
87
88 This value can be updated in the configuration file with the key `changelog_file` under `tool.commitizen`.
89
90 ```toml
91 [tool.commitizen]
92 # ...
93 changelog_file = "CHANGES.md"
94 ```
95
96 ### `--incremental`
97
98 Build from the latest version found in changelog.
99
100 Benefits:
101
102 - Useful if you have an existing changelog and want to use commitizen to extend it.
103 - Update unreleased area
104 - Allows users to manually edit the changelog without it being completely rewritten.
105
106 ```bash
107 cz changelog --incremental
108 ```
109
110 This flag can be set in the configuration file with the key `changelog_incremental` under `tool.commitizen`.
111
112 ```toml
113 [tool.commitizen]
114 # ...
115 changelog_incremental = true
116 ```
117
118 ### `--start-rev`
119
120 Start from a given git rev to generate the changelog. Commits before that rev will not be considered. This is especially useful for long-running projects adopting conventional commits, where old commit messages might fail to be parsed for changelog generation.
121
122 ```bash
123 cz changelog --start-rev="v0.2.0"
124 ```
125
126 This value can be set in the configuration file with the key `changelog_start_rev` under `tool.commitizen`
127
128 ```toml
129 [tool.commitizen]
130 # ...
131 changelog_start_rev = "v0.2.0"
132 ```
133
134 ### `--merge-prerelease`
135
136 Collects changes from prereleases into the next non-prerelease version. If you have a prerelease version followed by a normal release, the changelog will show the prerelease changes as part of the normal release. If not set, prereleases will be included as separate entries in the changelog.
137
138 ```bash
139 cz changelog --merge-prerelease
140 ```
141
142 This flag can be set in the configuration file with the key `changelog_merge_prerelease` under `tool.commitizen`
143
144 ```toml
145 [tool.commitizen]
146 # ...
147 changelog_merge_prerelease = true
148 ```
149
150 ### `--template`
151
152 Provide your own changelog Jinja template by using the `template` settings or the `--template` parameter.
153
154 ```bash
155 cz changelog --template="path/to/template.j2"
156 ```
157
158 ### `--unreleased-version`
159
160 There is usually a chicken-and-egg situation when automatically bumping the version and creating the changelog:
161
162 - If you bump the version first, you have no changelog yet, and it won't be included in the release of the created version.
163 - If you create the changelog before bumping the version, you usually don't have the latest tag, and the _Unreleased_ title appears.
164
165 By using `--unreleased-version`, you can prevent this situation.
166
167 Before bumping you can run:
168
169 ```bash
170 cz changelog --unreleased-version="v1.0.0"
171 ```
172
173 Remember to use the tag format instead of the raw version number.
174
175 For example, if your tag format includes a `v` prefix (e.g., `v1.0.0`), use that format. If your tag is the same as the raw version (e.g., `1.0.0`), use the raw version.
176
177 Alternatively, you can directly bump the version and create the changelog by running:
178
179 ```bash
180 cz bump --changelog
181 ```
182
183 ## Hooks
184
185 Supported hook methods:
186
187 - Per parsed message: Useful to add links to commits or issues
188 - End of changelog generation: Useful to send Slack or chat messages, or notify another department
189
190 Read more about hooks in the [customization page][customization]
191
192 [keepachangelog]: https://keepachangelog.com/
193 [semver]: https://semver.org/
194 [customization]: ../customization/config_file.md