git-cliff
repository·main·Indexed 10 days ago
https://github.com/orhun/git-cliffA high-performance, highly customizable changelog generator that automates the creation of changelogs from Git commit history. It leverages conventional commits, regex-powered custom parsers, and customizable templates. Version 2.13.1 supports hierarchical configuration via TOML, environment variables, or project manifests, and integrates with remote hosting providers like GitHub, GitLab, Gitea, Bitbucket, and Azure DevOps.
What's inside git-cliff
- git-cliff is a tool that generates changelog files from Git history. It works by utilizing conventional commits and supports regex-powered custom parsers. Users can customize the output format using a changelog template and a configuration file.
Improved Monorepo Support in git-cliff
mainIn recent versions,
git-cliffhas improved automatic discovery for monorepos. When running from a sub-directory within a Git repository:- The Git repository is discovered automatically.
- The configuration file is automatically found.
- The
include-pathis automatically set to the current directory.
This eliminates the need to manually specify
--include-pathand--repositorywhen working in sub-packages.Conditionally render content based on `bump_type`
mainThe determined version bump type is available in the release context as
{{ bump_type }}. You can use this to include specific text or sections in your changelog only when a certain type of release occurs.Available bump types:
majorminorpatch
{% if bump_type == "major" %} - This is a major release! {% endif %}Use Gitea context in templates
mainThe Gitea integration injects specific data into the template context.
Remote Context
You can access the repository owner and name using the
remote.giteaobject:{ "gitea": { "owner": "orhun", "repo": "git-cliff" } }Commit Author Context
Each commit object contains a
remotenested object with Gitea-specific metadata:{ "id": "...", "message": "...", "remote": { "username": "orhun", "pr_title": "some things have changed", "pr_number": 420, "pr_labels": ["rust"], "is_first_time": false } }Contributors Context
For each release, a
gitea.contributorslist is available containing metadata for all contributors in that release:{ "gitea": { "contributors": [ { "username": "orhun", "pr_title": "some things have changed", "pr_number": 420, "pr_labels": ["rust"], "is_first_time": true } ] } }Filter merge commits in templates
mainThe template context includes a
merge_commitboolean field. You can use this within a Jinja2filterto exclude merge commits from specific groups in your changelog.{% for group, commits in commits | filter(attribute="merge_commit", value=false) | group_by(attribute="group") %} ### {{ group | upper_first }} {% for commit in commits %} - {{ commit.message | upper_first }}\ {% endfor %} {% endfor %}Handle zero-based versioning schemes
mainIn zero-based versioning (e.g.,0.x.y), you may want to preserve the leading zero even during breaking changes to signal API stability levels. To implement this behavior, you must customize the bumping rules in yourgit-cliffconfiguration file using thebumpconfiguration section.Enable offline mode to prevent external API calls
mainWhen
offlineis enabled,git-cliffensures no external network requests are made, even if a remote is configured. This is useful for restricted environments or when running--bumped-version.You can enable offline mode via:
- Configuration parameter:
offline = true - CLI argument:
--offline - Environment variable:
GIT_CLIFF_OFFLINE
- Configuration parameter:
Use Azure DevOps context in templates
mainThe Azure DevOps integration injects specific data into the template context, allowing you to include usernames, PR numbers, and contributor lists in your changelog.
Remote Context
You can access the remote repository information using the
remote.azure_devopsobject:{ "azure_devops": { "owner": "myorg/myproject", "repo": "myrepo" } }Commit Context
Each commit object contains a
remotenested object with the following fields:username: The Azure DevOps username.pr_title: The title of the associated Pull Request.pr_number: The Pull Request number.pr_labels: A list of labels associated with the PR.is_first_time: A boolean indicating if this is the user's first contribution.
Example Template Usage:
{% for commit in commits %} * {{ commit.message | split(pat="\n") | first | trim }} {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif %} {% if commit.remote.pr_number %} in #{{ commit.remote.pr_number }}{%- endif %} {%- endfor %}Contributors Context
For each release, the
azure_devops.contributorslist is available, containing objects for each contributor:usernamepr_titlepr_numberpr_labelsis_first_time
Example Template Usage (First-time contributors):
{% for contributor in azure_devops.contributors | filter(attribute="is_first_time", value=true) %} * @{{ contributor.username }} made their first contribution in #{{ contributor.pr_number }} {%- endfor %}{ "id": "8edec7fd50f703811d55f14a3c5f0fd02b43d9e7", "message": "refactor(config): remove unnecessary newline from configs\n", "group": "🚜 Refactor", "remote": { "username": "orhun", "pr_title": "some things have changed", "pr_number": 420, "pr_labels": ["enhancement"], "is_first_time": false } }Integrate with Gitea for changelog data
mainYou can use Gitea integration to pull repository-specific data like usernames and pull request numbers into your changelog templates. This allows for more detailed contributor lists and commit descriptions.
Available variables:
- Usernames:
${{ commit.gitea.username }}or${{ contributor.username }} - Contributors list:
${{ gitea.contributors }} - Pull requests:
${{ commit.gitea.pr_number }}or${{ contributor.pr_number }}
## What's Changed - feat(commit): add merge_commit flag to the context by @orhun in #389 - test(fixture): add test fixture for bumping version by @orhun in #360 ## New Contributors - @someone made their first contribution in #360 - @cliffjumper made their first contribution in #389- Usernames:
Use GitLab context in templates
mainThe GitLab integration injects specific data into the template context, allowing you to include GitLab-specific metadata in your changelog.
Remote Context
Access the repository owner and name via
remote.gitlab:{ "gitlab": { "owner": "orhun", "repo": "git-cliff" } }Example usage for a tag URL:
https://gitlab.com/{{ remote.gitlab.owner }}/{{ remote.gitlab.repo }}/-/tags/{{ version }}Note: In GitLab CI, you can use
{{ get_env(name="CI_PROJECT_URL") }}instead.Commit Author Context
Each commit object contains a
remotenested object:username: GitLab usernamepr_title: Title of the Merge Requestpr_number: Merge Request numberpr_labels: List of labels on the MRis_first_time: Boolean indicating if this is the user's first contribution
Example template snippet:
{% for commit in commits %} * {{ commit.message | split(pat="\n") | first | trim }} {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif %} {% if commit.remote.pr_number %} in #{{ commit.remote.pr_number }}{%- endif %} {%- endfor %}Contributors Context
For each release, a
gitlab.contributorslist is available containing objects for each contributor:{ "gitlab": { "contributors": [ { "username": "orhun", "pr_title": "some things have changed", "pr_number": 420, "pr_labels": ["rust"], "is_first_time": true } ] } }Example to list new contributors:
{% for contributor in gitlab.contributors | filter(attribute="is_first_time", value=true) %} * @{{ contributor.username }} made their first contribution in #{{ contributor.pr_number }} {%- endfor %}Understand commit processing order
mainThe commit processing pipeline follows this order:
- Process commits: Apply preprocessors and initial parsing.
- Split commits: Split commits (e.g., by newline) and then process the resulting split commits.
This order allows you to use commit preprocessors to split a single commit into multiple conventional commits before they are parsed.
Auto-detect configuration files
maingit-cliffautomatically detects configuration files based on their presence in the project root.- If
cliff.tomlexists, it is used (even if a project manifest likeCargo.tomlis also present). - If
cliff.tomlis absent but a project manifest (e.g.,Cargo.toml) contains a[workspace.metadata.git-cliff.changelog]table,git-cliffwill use the configuration from that manifest. - If neither is found, it uses built-in defaults.
For Rust projects, you can simply run
git cliffinstead of specifying--config Cargo.tomlif you have configured the metadata table.$ git cliff # is same as $ git cliff --config Cargo.toml- If