Skip to content

Instantly share code, notes, and snippets.

@willeccles
Last active September 28, 2021 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willeccles/ae3ecb38099433c19e87ffc9d497f1eb to your computer and use it in GitHub Desktop.
Save willeccles/ae3ecb38099433c19e87ffc9d497f1eb to your computer and use it in GitHub Desktop.
Generate markdown changelogs from git tags and the commits between them
#!/bin/sh
set -e
# For each tag in the repository (sorted in reverse chronological order), print
# something like the following:
#
# ## Version <TAG>
# <Tag body, if it has one, but not the body of the pointed-to commit>
#
# ### Included changes
# - abc1234: <commit subject>
# - abc2345: <commit subject>
#
# The commits are listed in chronological order (older commits first). The
# "Included changes" section is not present for the first commit.
git tag --list --sort=-creatordate | while IFS= read -r tag; do
prev="$(git describe --tags --abbrev=0 "${tag}^" 2>/dev/null)" || true
printf "## Version %s\n" "$tag"
git for-each-ref "refs/tags/$tag" \
--format='%(if:equals=tag)%(objecttype)%(then)%(contents:body)%(end)'
if [ -n "$prev" ]; then
printf "### Included changes\n"
git log "${prev}..${tag}" --reverse --pretty='tformat:- %h: %s'
printf "\n"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment