|
| 1 | +## Initialize commitizen |
| 2 | + |
| 3 | +If it's your first time, you'll need to create a commitizen configuration file. |
| 4 | + |
| 5 | +The assistant utility will help you set up everything |
| 6 | + |
| 7 | +```sh |
| 8 | +cz init |
| 9 | +``` |
| 10 | + |
| 11 | +Alternatively, create a file `.cz.toml` in your project's directory. |
| 12 | + |
| 13 | +```toml |
| 14 | +[tool.commitizen] |
| 15 | +version = "0.1.0" |
| 16 | +update_changelog_on_bump = true |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### Bump version |
| 22 | + |
| 23 | +```sh |
| 24 | +cz bump |
| 25 | +``` |
| 26 | + |
| 27 | +This command will bump your project's version, and it will create a tag. |
| 28 | + |
| 29 | +Because of the setting `update_changelog_on_bump`, bump will also create the **changelog**. |
| 30 | +You can also [update files](./bump.md#version_files). |
| 31 | +You can configure the [version type](./bump.md#version-type) and [version provider](./config.md#version-providers). |
| 32 | + |
| 33 | +There are many more options available, please read the docs for the [bump command](./bump.md). |
| 34 | + |
| 35 | +### Committing |
| 36 | + |
| 37 | +Run in your terminal |
| 38 | + |
| 39 | +```bash |
| 40 | +cz commit |
| 41 | +``` |
| 42 | + |
| 43 | +or the shortcut |
| 44 | + |
| 45 | +```bash |
| 46 | +cz c |
| 47 | +``` |
| 48 | + |
| 49 | +#### Sign off the commit |
| 50 | + |
| 51 | +Run in the terminal |
| 52 | + |
| 53 | +```bash |
| 54 | +cz commit --signoff |
| 55 | +``` |
| 56 | + |
| 57 | +or the shortcut |
| 58 | + |
| 59 | +```bash |
| 60 | +cz commit -s |
| 61 | +``` |
| 62 | + |
| 63 | +### Get project version |
| 64 | + |
| 65 | +Running `cz version` will return the version of commitizen, but if you want |
| 66 | +your project's version you can run: |
| 67 | + |
| 68 | +```sh |
| 69 | +cz version -p |
| 70 | +``` |
| 71 | + |
| 72 | +This can be useful in many situations, where otherwise, you would require a way |
| 73 | +to parse the version of your project. Maybe it's simple if you use a `VERSION` file, |
| 74 | +but once you start working with many different projects, it becomes tricky. |
| 75 | + |
| 76 | +A common example is, when you need to send to slack, the changes for the version that you |
| 77 | +just created: |
| 78 | + |
| 79 | +```sh |
| 80 | +cz changelog --dry-run "$(cz version -p)" |
| 81 | +``` |
| 82 | + |
| 83 | +### Integration with Pre-commit |
| 84 | + |
| 85 | +Commitizen can lint your commit message for you with `cz check`. |
| 86 | + |
| 87 | +You can integrate this in your [pre-commit](https://pre-commit.com/) config with: |
| 88 | + |
| 89 | +```yaml |
| 90 | +--- |
| 91 | +repos: |
| 92 | + - repo: https://github.com/commitizen-tools/commitizen |
| 93 | + rev: master |
| 94 | + hooks: |
| 95 | + - id: commitizen |
| 96 | + - id: commitizen-branch |
| 97 | + stages: [push] |
| 98 | +``` |
| 99 | + |
| 100 | +After the configuration is added, you'll need to run: |
| 101 | + |
| 102 | +```sh |
| 103 | +pre-commit install --hook-type commit-msg --hook-type pre-push |
| 104 | +``` |
| 105 | + |
| 106 | +If you aren't using both hooks, you needn't install both stages. |
| 107 | + |
| 108 | +| Hook | Recommended Stage | |
| 109 | +| ----------------- | ----------------- | |
| 110 | +| commitizen | commit-msg | |
| 111 | +| commitizen-branch | pre-push | |
| 112 | + |
| 113 | +Note that pre-commit discourages using `master` as a revision, and the above command will print a warning. You should replace the `master` revision with the [latest tag](https://github.com/commitizen-tools/commitizen/tags). This can be done automatically with: |
| 114 | + |
| 115 | +```sh |
| 116 | +pre-commit autoupdate |
| 117 | +``` |
| 118 | + |
| 119 | +Read more about the `check` command [here](check.md). |
0 commit comments