This Bash script aggregates Git repository data into a structured file, providing the necessary context for AI models to generate readable changelogs. It captures commit history, file changes, diffs, and contributor stats since the last tagged release.
How It Works
The script performs four key operations:
- Records commit messages between the latest tag and HEAD
- Lists all modified files in this range
- Captures detailed diffs for each changed file
- Collects contributor statistics
The Script
#!/bin/bash
output_file="release_notes_data.txt"
latest_tag=$(git describe --tags --abbrev=0)
latest_tag_sha=$(git rev-list -n 1 $latest_tag)
echo "Release Notes since $latest_tag (SHA: $latest_tag_sha)" > $output_file
echo "=== COMMIT HISTORY ===" >> $output_file
git log --pretty=format:"%h %s" $latest_tag..HEAD --reverse >> $output_file
echo -e "\n\n=== CHANGED FILES ===" >> $output_file
git diff --name-only $latest_tag..HEAD >> $output_file
echo -e "\n\n=== FILE CHANGES ===" >> $output_file
for file in $(git diff --name-only $latest_tag..HEAD); do
echo -e "\n--- $file ---" >> $output_file
git diff $latest_tag..HEAD "$file" >> $output_file
done
echo -e "\n\n=== CONTRIBUTORS ===" >> $output_file
git shortlog -sn $latest_tag..HEAD >> $output_file
Usage
Run the script in your repository’s root directory.
It generates a release_notes_data.txt
file containing structured Git data, ready to use in any LLM as context to generate
the changelogs for your next release.
This automation helps maintain consistent, detailed changelogs while reducing manual effort in the release documentation process.
Example AI Prompt
Here’s a sample prompt to generate the changelog using the context file:
You are an expert in analyzing Git changes and writing clear, concise changelogs. Using the provided Git repository data, generate a changelog that:
1. Summarizes key changes and improvements
2. Groups related changes into categories (features, fixes, etc.)
3. Credits contributors appropriately
4. Maintains a professional yet readable tone
Format the changelog in Markdown with proper sections and bullet points.
git changes since last release:
{CONTENTS_OF_release_notes_data.txt}
This automation helps maintain consistent, detailed changelogs while reducing manual effort in the release documentation process.