Template Syntax
git-cliff uses Tera as its template engine. Tera has a syntax based on Jinja2 and Django templates.Delimiters
Tera uses three types of delimiters that cannot be changed:{{and}}for expressions (variables, function calls){%or{%-and%}or-%}for statements (control structures){#and#}for comments
Variables
Use double curly braces to output variables:Control Flow
Conditionals
Useif statements to conditionally render content:
Loops
Iterate over arrays withfor loops:
Whitespace Control
Add- to remove whitespace:
Filters
Filters transform values using the pipe| operator:
Built-in Tera Filters
Commonly used Tera filters:| Filter | Description | Example |
|---|---|---|
upper | Convert to uppercase | \{\{ "hello" | upper \}\} → HELLO |
lower | Convert to lowercase | \{\{ "HELLO" | lower \}\} → hello |
trim | Remove whitespace | \{\{ " text " | trim \}\} → text |
truncate | Truncate string | \{\{ "hello" | truncate(length=3) \}\} → hel... |
split | Split string | \{\{ "a,b,c" | split(pat=",") \}\} → [a, b, c] |
first | Get first item | \{\{ items | first \}\} |
last | Get last item | \{\{ items | last \}\} |
length | Get length | \{\{ items | length \}\} |
date | Format timestamp | \{\{ timestamp | date(format="%Y-%m-%d") \}\} |
default | Default value | \{\{ value | default(value="N/A") \}\} |
Custom git-cliff Filters
git-cliff provides custom filters for changelog generation:upper_first
Converts the first character to uppercase:Hello world
find_regex
Finds all occurrences of a regex pattern:[hello, hello]
replace_regex
Replaces all occurrences matching a regex pattern:hella warld
split_regex
Splits a string by a regex pattern:[hello, world,, hello, universe]
Macros
Macros are reusable template functions. Define them once and call them multiple times:Defining Macros
Macros with Parameters
Calling Macros
Real-World Example
Here’s a complete template fromcliff.toml:
- Defines a
remote_url()macro for GitHub URLs - Defines a
print_commit()macro for formatting commit entries - Conditionally renders version header with comparison links
- Groups commits by type (Features, Bug Fixes, etc.)
- Sorts scoped commits within each group
- Formats commits with scope, breaking change indicators, and links