Home

Awesome

<!DOCTYPE markdown><!-- markdownlint-disable first-line-h1 --><!-- spellchecker:ignore markdownlint -->

git-changelog

<!-- markdownlint-disable ul-style no-inline-html commands-show-output --> <!-- spellchecker:ignore () ENVFILE godoc macos rivy CHANGELOG CHANGELOG's GitLab tsuyoshiwada chglog snippetization --> <!-- spellchecker:ignore (emoji) tada -->

git-changelog

godoc.org MIT License

CHANGELOG generator implemented in Go (Golang). Anytime, anywhere, Write your CHANGELOG.

Table of Contents

Features

How it works

git-changelog internally uses the git command to get data to include in the CHANGELOG. The basic steps are as follows.

  1. Get all the tags.
  2. Get the commits contained between tagA and tagB.
  3. Execute with all tags corresponding to tag query that were specified in Step 1 and 2.

Getting Started

We will start with installation and introduce the steps up to the automatic generation of the configuration file and template.

Installation

<!-- Please install `git-changelog` in a way that matches your environment. #### [Homebrew](https://brew.sh) (for macOS users) ```bash $ brew tap rivy-go/git-changelog $ brew install git-changelog ``` #### [Scoop](https://scoop.sh) (for WinOS) ```shell $ scoop install git-changelog ``` #### Go users -->
$ go install github.com/rivy-go/git-changelog/cmd/git-changelog@latest

Install from source

$ git clone github.com/rivy-go/git-changelog
$ cd git-changelog
$ go install ./cmd/git-changelog

If you are using another platform, you can download a binary from the releases page and place it in a directory in your $PATH.

Test Installation

You can check with the following command whether the git-changelog command was included in a directory that is in your $PATH.

$ git-changelog --version
# outputs the git-changelog version

Quick Start

git-changelog requires configuration files and templates to generate a CHANGELOG.

However, it is a waste of time to create configuration files and templates from scratch.

Therefore we recommend using the --init option which will create them interactively :+1:

$ git-changelog --init

init option demo


You are now ready for configuration files and templates!

Let's immediately generate a CHANGELOG of your project. By doing the following simple command, Markdown for your CHANGELOG is displayed on stdout.

$ git-changelog

Use -o (--output) option if you want to output to a file instead of stdout.

$ git-changelog -o CHANGELOG.md

You now know basic usage of git-changelog!

In order to make a better CHANGELOG, please refer to the following document and customize it.

CLI Usage

$ git-changelog --help

USAGE:
  git-changelog [options] <tag query>

    There are the following specification methods for <tag query>.

    1. <old>..<new> - Commit contained in <old> tags from <new>.
    2. <name>..     - Commit from the <name> to the latest tag.
    3. ..<name>     - Commit from the oldest tag to <name>.
    4. <name>       - Commit contained in <name>.

OPTIONS:
  --init                                generate the git-changelog configuration file in interactive
  --config value, -c value              specifies a different configuration file to pick up (default: ".changelog/config.yml")
  --output value, -o value              output path and filename for the changelog; if not specified, output to stdout
  --next-tag value                      treat unreleased commits as specified tags (EXPERIMENTAL)
  --silent                              disable stdout output
  --no-color                            disable color output [$NO_COLOR]
  --no-emoji                            disable emoji output [$NO_EMOJI]
  --no-case                             disable case sensitive filters
  --tag-filter-pattern value, -p value  regular expression of tag filter; if specified, only matched tags will be picked
  --help, -h                            show help
  --version, -v                         print the version

EXAMPLE:

  $ git-changelog

    If <tag query> is not specified, it corresponds to all tags.
    This is the simplest example.

  $ git-changelog 1.0.0..2.0.0

    The above is a command to generate CHANGELOG including commit of 1.0.0 to 2.0.0.

  $ git-changelog 1.0.0

    The above is a command to generate CHANGELOG including commit of only 1.0.0.

  $ git-changelog $(git describe --tags $(git rev-list --tags --max-count=1))

    The above is a command to generate CHANGELOG with the commit included in the latest tag.

  $ git-changelog --output CHANGELOG.md

    The above is a command to output to CHANGELOG.md instead of standard output.

  $ git-changelog --config custom/dir/config.yml

    The above is a command that uses a configuration file placed other than ".changelog/config.yml".

tag query

You can specify which commits to include in the generation of CHANGELOG using <tag query>.

The table below shows Query patterns and summaries, and Query examples.

QueryDescriptionExample
<old>..<new>Commit contained in <new> tags from <old>.$ git-changelog 1.0.0..2.0.0
<name>..Commit from the <name> to the latest tag.$ git-changelog 1.0.0..
..<name>Commit from the oldest tag to <name>.$ git-changelog ..2.0.0
<name>Commit contained in <name>.$ git-changelog 1.0.0

Configuration

The git-changelog configuration is a yaml file. The default location is .changelog/config.yml.

Below is a complete list that you can use with git-changelog.

bin: git
style: ""
template: CHANGELOG.tpl.md
info:
  title: CHANGELOG
  repository_url: https://github.com/rivy-go/git-changelog

options:
  commits:
    filters:
      Type:
        - feat
    sort_by: Scope

  commit_groups:
    group_by: Type
    sort_by: Title
    title_maps:
      feat: Features

  header:
    pattern: "<regexp>"
    pattern_maps:
      - PropName

  issues:
    prefix:
      - #

  refs:
    actions:
      - Closes
      - Fixes

  merges:
    pattern: "^Merge branch '(\\w+)'$"
    pattern_maps:
      - Source

  reverts:
    pattern: "^Revert \"([\\s\\S]*)\"$"
    pattern_maps:
      - Header

  notes:
    keywords:
      - BREAKING CHANGE

bin

Git execution command.

RequiredTypeDefaultDescription
NString"git"-

style

CHANGELOG style. Automatic linking of issues and notices, initial value setting such as merges etc. are done automatically.

RequiredTypeDefaultDescription
NString"none"Should be "github" "gitlab" "bitbucket" "none"

template

Path for the template file. It is specified by a relative path from the setting file. Absolute paths are also ok.

RequiredTypeDefaultDescription
NString"CHANGELOG.tpl.md"-

info

Metadata for CHANGELOG. Depending on Style, it is sometimes used in processing, so it is recommended to specify it.

KeyRequiredTypeDefaultDescription
titleNString"CHANGELOG"Title of CHANGELOG.
repository_urlNStringnoneURL of git repository.

options

Options used to process commits.

options.commits

Options concerning the acquisition and sort of commits.

KeyRequiredTypeDefaultDescription
filtersNMap in ListnoneFilter by using Commit properties and values. Filtering is not done by specifying an empty value.
sort_byNString"Scope"Property name to use for sorting Commit. See Commit.

options.commit_groups

Options for groups of commits.

KeyRequiredTypeDefaultDescription
group_byNString"Type"Property name of Commit to be grouped into CommitGroup. See CommitGroup.
sort_byNString"Title"Property name to use for sorting CommitGroup. See CommitGroup.
title_mapsNMap in ListnoneMap for CommitGroup title conversion.

options.header

This option is used for parsing the commit header.

KeyRequiredTypeDefaultDescription
patternYStringnoneA regular expression to use for parsing the commit header.
pattern_mapsYListnoneA rule for mapping the result of HeaderPattern to the property of Commit. See Commit.

options.issues

This option is used to detect issues.

KeyRequiredTypeDefaultDescription
prefixNListnonePrefix used for issues. (e.g. #, #gh-)

options.refs

This option is for parsing references.

KeyRequiredTypeDefaultDescription
actionsNListnoneWord list of Ref.Action. See Ref.

options.merges

Options to detect and parse merge commits.

KeyRequiredTypeDefaultDescription
patternNStringnoneSimilar to options.header.pattern.
pattern_mapsNListnoneSimilar to options.header.pattern_maps.

options.reverts

Options to detect and parse revert commits.

KeyRequiredTypeDefaultDescription
patternNStringnoneSimilar to options.header.pattern.
pattern_mapsNListnoneSimilar to options.header.pattern_maps.

options.notes

Options to detect notes contained in commit bodies.

KeyRequiredTypeDefaultDescription
keywordsNListnoneKeyword list to find Note. A semicolon is a separator, like <keyword>: (e.g. BREAKING CHANGE).

Templates

The git-changelog template uses the text/template package. For basic usage please refer to the following.

text/template

If you are not satisfied with the prepared template please try customizing one.


The basic templates are as follows.

Example:

{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]

{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ range .CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}

{{- if .RevertCommits -}}
### Reverts
{{ range .RevertCommits -}}
- {{ .Revert.Header }}
{{ end }}
{{ end -}}

{{- if .MergeCommits -}}
### Pull Requests
{{ range .MergeCommits -}}
- {{ .Header }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

{{- if .Versions }}
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
{{ range .Versions -}}
{{ if .Tag.Previous -}}
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
{{ end -}}
{{ end -}}
{{ end -}}

See the godoc RenderData documentation for available variables.

Supported Styles

NameStatusFeatures
GitHub:white_check_mark:Mentions automatic link. Automatic link to references.
GitLab:white_check_mark:Mentions automatic link. Automatic link to references.
Bitbucket:white_check_mark:Mentions automatic link. Automatic link to references.

:memo: Even with styles that are not yet supported, it is possible to make ordinary CHANGELOG.

FAQ

<details> <summary>Why do not you output files by default?</summary> This is not for the purpose of completely automating the generation of CHANGELOG files, it is only for assisting generation.

It is ideal to describe everything included in CHANGELOG in your commits. But actually it is very difficult to do it perfectly.

There are times when you need to edit the generated output to write a great CHANGELOG.

By displaying it on the standard output, it makes it easy to change the contents.

</details> <details> <summary>Can I commit CHANGELOG changes before creating tags?</summary>

Yes, it can be solved by using the --next-tag flag.

For example, let's say you want to upgrade your project to 2.0.0. You can create CHANGELOG containing 2.0.0 as follows.

$ git-changelog --next-tag 2.0.0 -o CHANGELOG.md
$ git commit -am "release 2.0.0"
$ git tag 2.0.0

The point to notice is that before actually creating a tag with git, it is conveying the next version with --next-tag :+1:

This is a step that is necessary for project operation in many cases.

</details> <details> <summary>Can I generate a CHANGELOG based on certain tags?</summary>

Yes, it can be solved by use the --tag-filter-pattern flag.

For example, the following command will only include tags starting with "v":

$ git-changelog --tag-filter-pattern '^v'
</details>

TODO

Thanks

git-changelog is inspired by conventional-changelog. Thank you!

Contributing

We alway welcome your contributions :clap:

Development

  1. Fork https://github.com/rivy-go/git-changelog :tada:
  2. Create a feature branch :coffee:
  3. Run test suite with the $ make test command and confirm that it passes :zap:
  4. Commit your changes :memo:
  5. Rebase your local changes against the master branch :bulb:
  6. Create new Pull Request :love_letter:

Bugs, feature requests and comments are more than welcome in the issues.

Feedback

I would like to make git-changelog a better tool. The goal is to be able to use in various projects.

Therefore, your feedback is very useful. I am very happy to tell you your opinions on Issues and PR :heart:

CHANGELOG

See CHANGELOG.md

Related Projects

License

MIT © tsuyoshiwada