On GitHub, f/git-rewrite-commits has picked up 1.4k stars, Developer Tools, TypeScript. AI-powered git commit message rewriter using Ollama or GPT
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Automatically rewrite your entire git commit history with better, conventional commit messages using AI. Perfect for cleaning up messy commit histories before open-sourcing projects or improving repository maintainability.
📖 Read the blog post: Fix Your Messy Commit History with AI
Important Disclaimer
This tool rewrites git history, which is generally NOT recommended for shared repositories!
When to use:
Personal projects before making them public
Feature branches before merging (with team agreement)
Cleaning up local commits before pushing
Preparing repositories for open-sourcing
When NOT to use:
On shared branches without team coordination
After pushing commits that others have pulled
On main/master branches of team projects
In repositories where commit hashes are referenced
Remember: Rewriting history changes commit hashes and requires force-pushing, which can disrupt your team's workflow.
Security & Privacy
🔒 Important Privacy Notice: When using remote AI providers (OpenAI), this tool sends your file lists and diffs to external APIs.
Security Features:
✅ Explicit consent required before sending data to remote providers
✅ Automatic redaction of API keys, passwords, and private keys
✅ Local processing option via Ollama (no data leaves your machine)
✅ Opt-in hooks - all hooks require explicit enabling via git config
# Full command name
npm install -g git-rewrite-commits
# Or install the short alias (grec = git-rewrite-commits)
npm install -g grec
# Both work identically:
git-rewrite-commits --help
grec --help # Same thing, just shorter!
✅ Works on all platforms: Windows, macOS, Linux
💡 Tip: grec is a shorter alias for git-rewrite-commits - use whichever you prefer!
Quick Hook Installation
Step 1: Install or update the AI commit message hooks
npx git-rewrite-commits --install-hooks
# or with the short alias:
npx grec --install-hooks
💡 Updates existing hooks: If hooks already exist, they'll be updated to the latest version. Non-git-rewrite-commits hooks are backed up before replacement.
Step 2: Enable the hooks you want (opt-in required for security):
# Option A: Enable message preview before commit
git config hooks.preCommitPreview true
# Option B: Enable automatic message generation
git config hooks.prepareCommitMsg true
# Or enable both for the full experience!
# For privacy: use local Ollama instead of remote OpenAI
git config hooks.commitProvider ollama
git config hooks.providerModel llama3.2 # Optional: specify model
Step 3: Configure your AI provider:
# Option A: OpenAI (sends data to remote API)
export OPENAI_API_KEY="your-api-key" # Unix/macOS
# set OPENAI_API_KEY="your-api-key" # Windows
# Option B: Ollama (local processing, recommended for sensitive repos)
ollama pull llama3.2
ollama serve
# Option C: Ollama on a custom server/port
export OLLAMA_URL="http://192.168.1.100:11434" # Unix/macOS
# set OLLAMA_URL=http://192.168.1.100:11434 # Windows
See QUICK_START.md for detailed setup guide
Additional Configuration (Optional)
# Set your template format
git config hooks.commitTemplate "[JIRA-XXX] feat: message"
# Set language
git config hooks.commitLanguage "es" # Spanish, French, etc.
# Set specific model
git config hooks.providerModel "gpt-4" # or "gpt-3.5-turbo", "llama3.2", etc.
# Set custom Ollama server URL (if not using localhost:11434)
git config hooks.ollamaUrl "http://192.168.1.100:11434"
Custom Project Guidelines with COMMIT_MESSAGE.md
You can provide project-specific commit message guidelines that the AI will follow by creating a COMMIT_MESSAGE.md file. The tool searches for this file in the following locations (in order):
Project root - ./COMMIT_MESSAGE.md
Git directory - ./.git/COMMIT_MESSAGE.md
GitHub directory - ./.github/COMMIT_MESSAGE.md
Example COMMIT_MESSAGE.md:
# Project Commit Guidelines
## Requirements
- Use conventional commits with these scopes: auth, api, ui, db
- Include ticket numbers when available (e.g., JIRA-123)
- Security changes must be clearly marked
- Breaking changes need BREAKING CHANGE in the message
## Project Context
This is a financial services API that handles sensitive data.
Emphasize security, compliance, and performance in commit messages.
See COMMIT_MESSAGE.md.example in this repository for a complete example.
Usage
Command Examples
# Using the full command name
npx git-rewrite-commits [options]
# Or using the short alias (grec)
npx grec [options]
Common use cases:
# Rewrite entire git history
npx git-rewrite-commits
# Preview changes without applying (dry run)
npx git-rewrite-commits --dry-run
# Generate commit message for staged changes
npx git-rewrite-commits --staged
# Process only last 10 commits
npx git-rewrite-commits --max-commits 10
# Use custom AI model
npx git-rewrite-commits --model gpt-4
# Use local AI with Ollama
npx git-rewrite-commits --provider ollama
# Install/update git hooks
npx git-rewrite-commits --install-hooks
Real-World Examples
Automatic Commit Message Generation
Two Smart Hooks:
pre-commit: Preview AI message and optionally replace bad commit messages
prepare-commit-msg: Automatically generate or use approved messages
# Install the hooks (using either command)
npx git-rewrite-commits --install-hooks
# or
npx grec --install-hooks
# Enable them (opt-in for security)
git config hooks.preCommitPreview true # Preview before commit
git config hooks.prepareCommitMsg true # Auto-generate in editor
# Configure provider
git config hooks.commitProvider ollama # or use OpenAI with OPENAI_API_KEY
git config hooks.providerModel llama3.2 # Optional: specify model
Now when you run git commit:
With pre-commit: You'll see a preview of the AI message first
With prepare-commit-msg: The AI message appears in your editor
Manual Rewriting for Existing Commits
# Clean up the last 5 commits before pushing
echo "🔧 Improving commit messages before push..."
npx git-rewrite-commits --max-commits 5 --dry-run
echo "Apply changes? (y/n)"
read answer
if [ "$answer" = "y" ]; then
# Shell alias
alias fix-last-commit='npx git-rewrite-commits --max-commits 1 --skip-backup'
alias fix-branch='npx git-rewrite-commits --max-commits 20'
# Usage: fix-last-commit
Team Workflow: Feature Branch Cleanup
Before creating a pull request:
# 1. Check what needs fixing
npx git-rewrite-commits --dry-run --max-commits 10
# 2. Apply improvements
npx git-rewrite-commits --max-commits 10
# 3. Force push to your feature branch
git push --force-with-lease origin feature-branch
CI/CD Integration
Add to your CI pipeline (e.g., GitHub Actions) for PR validation:
- name: Check Commit Quality
run: |
npx git-rewrite-commits --dry-run --max-commits ${{ github.event.pull_request.commits }}
# This will show which commits would be improved
Preparing for Open Source
Before making a private repo public:
# Fix all commits with custom template
npx git-rewrite-commits \
--template "feat(scope): message" \
--language en \
--no-skip-well-formed
# Review the changes
git log --oneline -20
# If satisfied, force push
git push --force-with-lease origin main
How It Works
Analyze: Reads your staged changes or commit history
Generate: Uses AI to create meaningful, conventional commit messages
Apply: Updates your commits with better messages
Smart Message Replacement
When you use git commit -m "bad message", pre-commit can:
Suggest a better AI-generated message
Replace your bad message when you approve it
Show what was replaced in the commit editor
History Rewriting Process
Creates backup: Saves current branch state
Rewrites history: Uses git filter-branch to apply new messages
Provides recovery: Keeps backup branch for restoration if needed
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Fork the repository
Create your feature branch (git checkout -b feature/AmazingFeature)
Commit your changes (using conventional commits!)
Push to the branch (git push origin feature/AmazingFeature)
Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Bug Reports
If you discover any bugs, please create an issue here.
Contact
For questions and support, please open an issue in the GitHub repository.
Remember: Always backup your repository before rewriting history! 🔒
How active is development on f/git-rewrite-commits?
The most recent commit recorded on f/git-rewrite-commits was 5 months ago, based on the GitHub push timestamp. The repository has 59 forks — one of the better signals of community interest.
Is f/git-rewrite-commits open source?
Yes — f/git-rewrite-commits ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/f/git-rewrite-commits.
What license does f/git-rewrite-commits use?
f/git-rewrite-commits is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is f/git-rewrite-commits associated with?
GitHub's repository topics for f/git-rewrite-commits: "git", "pre-commit-hook". TopGit's editorial category is Developer Tools.
Where can I see f/git-rewrite-commits in action?
The project maintains a homepage at https://blog.fka.dev/git-rewrite-commits/. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about f/git-rewrite-commits?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/f/git-rewrite-commits is the definitive source.
Read full README in the tab above.
Curious whether git-rewrite-commits is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about git-rewrite-commits.