Skip to content

Instantly share code, notes, and snippets.

@ravener
Created June 24, 2022 07:58
Show Gist options
  • Save ravener/7c95e5e58a7ce912efb10e7c76e20b3b to your computer and use it in GitHub Desktop.
Save ravener/7c95e5e58a7ce912efb10e7c76e20b3b to your computer and use it in GitHub Desktop.
Generate CHANGELOG.md from git tags
#!/usr/bin/bash
# A bash script to generate a markdown changelog from git tags
# Run this inside a git repository to generate CHANGELOG.md file
if [ ! -d ".git" ]; then
echo "Error: Not a git repository"
exit 1
fi
OUTPUT=""
BEFORE=""
for tag in `git tag --list --sort=-version:refname`; do
if [ ! -z "$BEFORE" ]; then
OUTPUT+="# $tag ($(git log -1 --date=short --pretty=%ad $tag))\n"
OUTPUT+=`git log $tag...$BEFORE --pretty="- %s"`
OUTPUT+="\n\n"
fi
BEFORE=$tag
done
# Include the first tag too. (last in our list)
# This is because the loop above records BEFORE and tries next one
# When this tag comes, there's no next so it gets left behind.
OUTPUT+="# $BEFORE ($(git log -1 --date=short --pretty=%ad $BEFORE))\n"
OUTPUT+=`git log $BEFORE --pretty="- %s"`
echo -e "$OUTPUT"
echo -e "$OUTPUT" > CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment