Linux下使用git-cliff生产CHANGELOG.md

简介

git-cliff 是一个高度可定制的更新日志生成器,遵循常规的 Commit 规范。
git-cliff 可以通过利用传统的 commits 以及由 regex 驱动的自定义解析器,从 Git 历史中生成更新日志文件。更新日志模板可以用配置文件定制,以符合所需的格式。

在这里插入图片描述

下载

直接在https://github.com/orhun/git-cliff/releases下载即可,这里以下载git-cliff-0.9.1-x86_64-unknown-linux-musl.tar.gz为例,下载地址为git-cliff-0.9.1-x86_64-unknown-linux-musl.tar.gz

注意下载的版本,git-cliff-0.9.1-x86_64-unknown-linux-musl.tar.gz其中的git-cliff是静态编译的;而git-cliff-0.9.1-x86_64-unknown-linux-gnu.tar.gz其中的git-cliff是动态编译的,需要的glibc版本为GLIBC_2.29,这个一定需要注意。

git-cliff-0.9.1-x86_64-unknown-linux-musl.tar.gz
git-cliff-0.9.1-x86_64-unknown-linux-gnu.tar.gz
压缩包名字一个是musl,一个是gnu。

注意,这里下载的版本为可执行程序,不是源码。解压缩后文件夹中的git-cliff即为其可执行程序。

使用

git-cliff是根据提交记录来生产CHANGELOG的,所以提交记录一定要按照一定的格式。
如果是新功能,需要"feat:内容"的形式进行提交;如果是修改bug,需要使用"fix:内容"的形式。其他的格式,可以参考git-cliff的配置文件。提交时的内容格式为[提交类型:内容], 中间的冒号必须使用英文下的冒号,这点一定要注意。

命令git-cliff --init用来生成配置文件git-cliff.toml,其中的内容有如下片段:

# regex for parsing and grouping commits
commit_parsers = [
    { message = "^feat", group = "Features"},
    { message = "^fix", group = "Bug Fixes"},
    { message = "^doc", group = "Documentation"},
    { message = "^perf", group = "Performance"},
    { message = "^refactor", group = "Refactor"},
    { message = "^style", group = "Styling"},
    { message = "^test", group = "Testing"},
    { message = "^chore\\(release\\): prepare for", skip = true},
    { message = "^chore", group = "Miscellaneous Tasks"},
    { body = ".*security", group = "Security"},
]

group字段中,Features代表新功能Bug Fixes代表bug修改Documention代表文件Performance代表提升性能refactor代表重构等。也可以将group字段该为汉字,这样在生成CHANGELOG时就会以汉字进行分段。

意外一定需要注意的是,在打标签时,一定要使用格式如[v版本号]进行标签创建,因为配置文件git-cliff.toml中有如下约定,匹配tag时,使用小写v开始进行匹配的。

# glob pattern for matching git tags
tag_pattern = "v[0-9]*"

使用简单的git-cliff命令即可生成changelog,输出的内容如下:

# Changelog

All notable changes to this project will be documented in this file.

## [1.0.1] - 2022-10-15

### Bug Fixes

- 添加文件3.txt

## [1.0.0] - 2022-10-15

### Bug Fixes

- 1 在文件1.txt中添加部分内容

### Features

- 1 创建新文件1.txt

详细的使用git-cliff的使用方法,使用命令git-cliff -h即可:

[root@VM-12-15-centos test_xxx]# ./git-cliff -h
git-cliff 0.9.2
git-cliff contributors <git-cliff@protonmail.com>
A highly customizable changelog generator ⛰️ 

USAGE:
    git-cliff [FLAGS] [OPTIONS] [--] [RANGE]

FLAGS:
    -v, --verbose       Increases the logging verbosity
    -i, --init          Writes the default configuration file to cliff.toml
    -l, --latest        Processes the commits starting from the latest tag
        --current       Processes the commits that belong to the current tag
    -u, --unreleased    Processes the commits that do not belong to a tag
        --date-order    Sorts the tags chronologically
        --context       Prints changelog context as JSON
    -h, --help          Prints help information
    -V, --version       Prints version information

OPTIONS:
    -c, --config <PATH>                Sets the configuration file [env: GIT_CLIFF_CONFIG=] [default: cliff.toml]
    -w, --workdir <PATH>               Sets the working directory [env: GIT_CLIFF_WORKDIR=]
    -r, --repository <PATH>            Sets the git repository [env: GIT_CLIFF_REPOSITORY=]
        --include-path <PATTERN>...    Sets the path to include related commits [env: GIT_CLIFF_INCLUDE_PATH=]
        --exclude-path <PATTERN>...    Sets the path to exclude related commits [env: GIT_CLIFF_EXCLUDE_PATH=]
        --with-commit <MSG>...         Sets custom commit messages to include in the changelog [env: GIT_CLIFF_WITH_COMMIT=]
    -p, --prepend <PATH>               Prepends entries to the given changelog file [env: GIT_CLIFF_PREPEND=]
    -o, --output <PATH>                Writes output to the given file [env: GIT_CLIFF_OUTPUT=]
    -t, --tag <TAG>                    Sets the tag for the latest version [env: GIT_CLIFF_TAG=]
    -b, --body <TEMPLATE>              Sets the template for the changelog body [env: GIT_CLIFF_TEMPLATE=]
    -s, --strip <PART>                 Strips the given parts from the changelog [possible values: header, footer, all]
        --sort <SORT>                  Sets sorting of the commits inside sections [default: oldest] [possible values: oldest, newest]

ARGS:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值