Create an unopionated CHANGELOG.md from Git commit history (see Details)
hh lohmann <hh.lohmann@gmail.com>
Last 5 changes - see CHANGELOG file for full list and details
CLI without parameters
commits-to-changelog
no parameters
Default settings can be overwritten by key-value pairs in an object as value for a key “commits-to-changelog” in a package.json belonging to the repo for which a CHANGELOG.md should be created, e.g.
// package.json
{
"version": "...",
"commits-to-changelog": {
"headerDefault": "Latest",
"headerMerged": "Implement",
"linesToReadme": 5
},
"dependencies": {
"...": "..."
}
}
Array of RegExp: Filter out commits / commit types identified by a message matching one of the RegExps in the array
^exp$ exactly like /^exp$/ (i,e. interprets unquoted / at start and end as RegExp delimiters, not as literal / part of the RegExp)Boolean: Filter out commit types that are rather not relevant for users by matching commit messages against RegExps /^bump version$/i, /^changelog$/i, /^dev:/i, /^[Hh]ousekeeping/i, /^planning/i, /[Rr]efactoring/i, /tests/i
String to use as header for listing commits that do not belong to a defined Git tag
String to use as header for listing Merged Branches with a commit message of the form Merge branch '<branch name>'
Write defined number of lines from the start of CHANGELOG.md also to an existing section with heading “Changelog” (or “CHANGELOG” or any preferred case) in README.md
Reject creating a Changelog if commits without associated Git tag exist
no return
See the CHANGELOG.md of this project
See the section Changelog in this file (cf. details for optional setting linesToReadme under Settings)
Branches that were merged as an explicit commit (i.e. no fast-forward) are listed as indented blocks with the message of the merge commit as a title line, e.g.
* dddb03a (HEAD -> master, origin/master) fix/unclear-error
|\
| * f6f8cd1 Update error message
|/
* 4bd8518 Update token hash to include encoded user name
as
- fix/unclear-error
- Update error message
- Update token hash to include encoded user name
If the merge’s commit message has the form Merge branch '<branch name>' it will be replaced by Include (results of) separate branch '<branch-name>', e.g.
* dddb03a (HEAD -> master, origin/master) Merge branch 'fix/unclear-error'
...
as
- Include (results of) separate branch 'fix/unclear-error'
...
none
CLIs should be installed systemwide (“global”). Strip off the -g parameter or replace it by a -D (as development dependency, -d for Bun) to explicitly restrict to a repo bounded usage.
Pick for your preferred package manager:
npm i -g commits-to-changelog
pnpm i -g commits-to-changelog
bun i -g commits-to-changelog
# For Yarn you should double check docs for your and / or
# current Yarn version, newer versions do not treat `i package_name`
# as an alias for `add ...` and exclude global installations
yarn add commits-to-changelog
The resulting CHANGELOG.md has the simple structure
# Changelog
## {groupheader} ({date})
- [{commit-subject}]({commit-link})
- [{commit-subject}]({commit-link})
## {groupheader} ({date})
- [{commit-subject}]({commit-link})
- [{commit-subject}]({commit-link})
(...)
where # Changelog is the title, a Markdown atx heading (i.e. using “#”) of level 1 with the text “Changelog”, followed by an empty line, and lists of commits that are grouped by
true (default): the Git tag they are associated withfalse:
so that the applicable Git tag / package.json version or the headerDefault becomes the {groupheader} that together with the date of the Git tag or else the current date constitutes a Markdown heading of level 2 under which associated commits are listed as
[{commit-subject}]({commit-link}) formed by the subject of the commit and the remote entry for the commit what is usually a page including a Git diff for the commitBesides the existence and characteristics of Git tags, a possible package.json and Git remote defintions the actually resulting CHANGELOG.md can be shaped by Settings.
The (initial) code here is forked from git-to-changelog, an already very good solution, but due to a hardwired search path ‘../../package.json’ - mimicking npm’s way of structuring a node_modules folder - not usable with pnpm, and while fixing this some other little things were changed / improved (see CHANGELOG) and made the initial little fix grow into an own project