The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Generate a changelog from git commits

To generate a changelog from git commits, here’s a straightforward approach you can use. This process extracts commit messages and formats them into a changelog style. Below is a step-by-step guide and a sample script to automate this:


Manual Method (Basic)

Run this command in your Git repository to get a simple list of commits:

bash
git log --pretty=format:"- %s (%h)" --no-merges
  • %s — commit message subject

  • %h — short commit hash

  • --no-merges — exclude merge commits (optional)

This outputs a simple changelog-style list, e.g.:

pgsql
- Fix issue with user login (a1b2c3d) - Update README with installation steps (d4e5f6g) - Add new feature for data export (h7i8j9k)

Automated Script for More Detailed Changelog

If you want to generate a more structured changelog (grouped by type or date), here is a sample Bash script that extracts commits since the last tag, categorizes them, and outputs a changelog.

bash
#!/bin/bash # Get the latest tag LAST_TAG=$(git describe --tags --abbrev=0) # Get commits since last tag COMMITS=$(git log ${LAST_TAG}..HEAD --no-merges --pretty=format:"%s") echo "## Changelog since ${LAST_TAG}" echo "" # You can add commit message parsing here to categorize, for example: echo "$COMMITS" | while read -r line; do if [[ "$line" =~ ^feat ]]; then echo "- Feature: ${line#feat: }" elif [[ "$line" =~ ^fix ]]; then echo "- Bug Fix: ${line#fix: }" else echo "- Other: $line" fi done

Using Tools

For professional changelog generation, consider using tools like:

  • git-chglog — generates changelogs based on commit history and templates.

  • standard-version — automates versioning and changelog generation based on conventional commits.

  • auto-changelog — generates changelogs from git tags and commit messages.


Let me know if you want me to generate a changelog from an example commit history or if you need a script tailored to a specific commit message style!

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About