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