Skip to main content

Release Notes Downloads GitHub CI Status License: MIT

Extract Git History in an LLM Friendly Way

A tool to extract and filter git commit history, making it easy to pipe to AI tools for changelog generation and summaries.

Features

  • Extract git commits with metadata (SHA, date, files, message)
  • Filter commits by time range or starting commit
  • Automatic stacked PR detection with gh stack support (opt out with --no-stack-aware)
  • Extract and filter git trailers (e.g., Co-authored-by, User-Facing)
  • Output in simple text or JSON format
  • Pipe output to AI tools (OpenAI, Gemini, Claude) for automated summarization

Installation

No installation needed! The tool can be run directly:

uv run git-history-extraction --help

Install as Package

pip install git-history-extraction

Library Usage

You can also use git-history-extraction as a Python library:

from git_history_extraction import extract_history

# Returns a list of dictionaries with sha, date, body, files, etc.
commits = extract_history(
    since="last monday", trailers="User-facing", include_stats=True
)

for commit in commits:
    print(f"{commit['sha']}: {commit['body']}")

Usage

Basic Examples

Extract commits from the last 24 hours (default):

git-history-extraction

Extract commits from the last 7 days:

git-history-extraction --since "7 days ago"

Extract commits from a specific repository:

git-history-extraction --repo /path/to/repo --since "1 week ago"

Output Formats

Simple text format (default):

git-history-extraction --since "1 day ago"

JSON format for piping to other tools:

git-history-extraction --since "1 day ago" --format json

Commit Range Selection

By time range:

git-history-extraction --since "2024-01-01"

From a specific commit to HEAD:

git-history-extraction --since-commit abc1234

Unique to a branch:

# Gets commits on 'feature-branch' that are not on the default branch (e.g. main)
git-history-extraction --branch feature-branch

# Defaults to the current active branch if no branch is specified
git-history-extraction --branch

Stacked PRs (gh stack):

# Automatically detects if the current branch is part of a gh stack and compares against its parent branch
git-history-extraction

# Explicitly specify a branch within a stack
git-history-extraction --branch feature-2

# Manually specify a parent branch/commit to compare against
git-history-extraction --branch feature-3 --stack-parent feature-1

# Opt out of stack detection and compare branch directly against default branch (e.g. main)
git-history-extraction --branch feature-2 --no-stack-aware

Stack-aware comparison automatically detects stacks targeting any trunk (e.g. main, develop, or release branches), correctly skips merged or queued ancestor PRs, excludes commits from squash-merged downstack ancestors so they don't leak into child diffs, and falls back gracefully if downstack parent branches were deleted locally.

Git Trailers

Extract specific trailers only (case-insensitive):

git-history-extraction --since "1 week ago" --trailers "co-authored-by,reviewed-by"

Piping to AI Tools for Summarization

This tool extracts and formats git history, making it easy to pipe to AI tools for summarization. The tool itself does not perform AI summarization—it prepares the data so you can use your preferred AI tool.

The tool enables you to extract targeted slices of git history for different audiences. For example, use git trailers like User-Facing: to mark end-user changes, then extract and pipe them to AI for changelogs or internal notifications.

Creating Structured Git Trailers with AI

Combine with aiautocommit to automatically generate git trailers during commits. This creates a structured history that can be easily filtered and summarized for different audiences.

Example custom commit prompt for aiautocommit:

# IMPORTANT: Your Instructions

You are an expert software developer. Generate a commit message from the `git diff` output below using these rules:

## 1. Subject Line

- Use a conventional commit prefix:
  - `feat`: New features
  - `fix`: Bug fixes, including user-visible design or style fixes.
  - `docs`: Changes only to internal documentation (e.g., `.md`, `.rst`) or code comments.
  - `style`: Formatting, linting, or code style changes in code files.
  - `refactor`: Code structure improvements (no behavior changes).
  - `build`: Updates to build scripts or configs (e.g., `Makefile`, `Justfile`, `Dockerfile`, `package.json`).
  - `deploy`: Deployment script or IAC updates.
  - `test`: Changes to tests
- Add optional scope in parentheses when changes affect a specific module (e.g., `feat(auth): add login`)
- Limit to 50 characters after the prefix and scope.
- Use imperative mood (e.g., "improve layout").
- Describe the intent or outcome (e.g., "prevent text overflow" not "add break-all").
- Be specific about the change ("validate email format" not "improve validation").

## 2. Extended Commit Message

- Include only if changes have non-obvious implications, fix complex bugs, or introduce breaking changes.
- Separate from subject with one blank line.
- Use markdown bullets focusing on **why** the change was needed and **what impact** it has.
- Mention side effects, user impact, or important trade-offs.

## 3. User-facing Changes

If the change is something that a end-user (not internal admin!) would see, include a `User-facing:` git trailer with a sentence
or two explaining, to the user, what they would see differently because of this change.

## 4. General Guidelines

- Prioritize the purpose of changes over listing tools or properties used.
- Keep concise; avoid obvious or verbose details.
- Always generate a message based on the diff, even with limited context.

## 5. Scopes

Optional scopes (e.g., `feat(api):`):

- `match`: frontend or backend changes tied
- `site`: content, additional pages, etc for the static site content
- `internal-admin`: internal admin changes (including CMS)

With this setup, commits automatically get User-facing: trailers. You can then extract and summarize them:

# Extract only user-facing changes from the last sprint
git-history-extraction --since "last monday" --trailers "User-facing" | \
  gemini -i "Create a user-friendly changelog from these changes"

Using with Gemini CLI

Extract user-facing changes and generate a non-technical summary:

git-history-extraction --repo . --since "last monday" \
  --trailers "User-Facing" | \
  gemini -i "This is a compressed git history identifying user-facing changes. \
Can you write a 1-2 sentence overview of the changes, with a list of bullets \
identifying changes. This is for a non-technical internal audience, letting \
them know what the development team has done. Separate into 'new' and 'fixed' \
sections. Include a 'Updates Since' with the date of the first commit in the \
history. Remove fluff, keep it concise and information dense."

Using the OpenAI Playground Script (Optional)

An optional playground script is included that demonstrates OpenAI integration:

# Generate summary with OpenAI
git-history-extraction --since "1 week ago" --format json | \
  uv run playground/summarize_commits.py

# Preview the prompt without calling OpenAI
git-history-extraction --since "1 week ago" --format json | \
  uv run playground/summarize_commits.py --dump-prompt

Requirements:

  • OPENAI_API_KEY environment variable
  • The script uses GPT-4o-mini by default

This is just an example—you can pipe to any AI tool you prefer. See playground/README.md for more details.

Output Format

Simple Format

Each commit is displayed with:

  • Commit: SHA hash
  • Date: ISO 8601 timestamp
  • Files: Comma-separated list of changed files
  • Message: Commit body with trailers removed

JSON Format

Array of commit objects:

[
  {
    "sha": "abc123...",
    "date": "2024-10-31T08:00:00-06:00",
    "body": "commit message with trailers",
    "files": ["file1.py", "file2.md"]
  }
]

Options

Option Description Default
--since TEXT ISO date/time or relative time "24 hours ago"
--since-commit TEXT Start from specific commit (overrides --since) None
--since-last-tag Extract commits since the Nth most recent tag (Tag[N]..Tag[N-1]). 0 = LatestTag..HEAD False
--branch TEXT Get commits unique to a branch. If omitted, uses current branch. (overrides --since) None
--repo DIRECTORY Path to git repository . (current directory)
--trailers TEXT Comma-separated trailer keys to extract None (show all)
--stack-aware / --no-stack-aware Automatically detect and use parent branch in gh stack as comparison point True
--stack-parent TEXT Explicitly specify the parent branch or commit to compare against in a stacked workflow None
--remote / --local Use remote references instead of local --remote
--format [simple|json] Output format simple

How It Works

  • Uses git log with custom formatting for efficient single-pass extraction
  • Parses commit metadata, body, and file changes in one command
  • Intelligently extracts git trailers from commit messages
  • No per-commit subprocess calls for optimal performance

Limitations

  • Large commit ranges may generate significant output; consider narrowing the time range
  • This tool extracts and formats data only—AI summarization requires external tools
  • Git must be available in PATH

Local CLI development

Run just install_editable to install this checkout globally in editable mode. Source changes are reflected without reinstalling.

This requires uv, just, zsh, and jq. If mise is available, the recipe also updates every installed pipx:git-history-extraction environment so mise can use the local checkout. Re-run after mise upgrades, which replace those editable installations.

This project was created from iloveitaly/python-package-template

Metadata

Release files for git-history-extraction 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-history-extraction 0.12.0
File Size Uploaded Provenance Actions
git_history_extraction-0.12.0.tar.gz 17.3 kB Without provenance Details for git_history_extraction-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for git-history-extraction 0.12.0
File Interpreter ABI Platform Actions
git_history_extraction-0.12.0-py3-none-any.whl Python 3 none any Details for git_history_extraction-0.12.0-py3-none-any.whl

Total release size: 35.4 kB

Release files / git_history_extraction-0.12.0.tar.gz

Download URL git_history_extraction-0.12.0.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5b5dbfd788ab80f4ed9848ac8ee48e997fc3a35610ad5bfc6b95cf0265851146
BLAKE2b-256 checksum
How to use checksums
43cd9f7590902f492540545e68f724aa4437d89ec24be58aebc8ed877e3acaf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / git_history_extraction-0.12.0-py3-none-any.whl

Download URL git_history_extraction-0.12.0-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbe1d2ad149b7a2e3d203038e5711ea84d7a638ce43311c70909e4683540d0c2
BLAKE2b-256 checksum
How to use checksums
d3f7fd7f3c52e46bc83c624bf6033e0ec0491e4c2b80038a6187b06a89a9c323
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for git-history-extraction 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page