rewrite-commit-history
Rewrite a feature branch's commit history into clean conventional commits that tell a progressive, linear story. Handles backup, soft reset, and atomic recommit. Use when: (1) Cleaning up messy WIP commits before PR, (2) Reorganizing commits into logical units, (3) Converting commits to conventional commit format. Triggers on: "rewrite history", "clean up commits", "rewrite commits", "conventional commits", "squash and rewrite", "reorganize commits".
Best use case
rewrite-commit-history is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Rewrite a feature branch's commit history into clean conventional commits that tell a progressive, linear story. Handles backup, soft reset, and atomic recommit. Use when: (1) Cleaning up messy WIP commits before PR, (2) Reorganizing commits into logical units, (3) Converting commits to conventional commit format. Triggers on: "rewrite history", "clean up commits", "rewrite commits", "conventional commits", "squash and rewrite", "reorganize commits".
Teams using rewrite-commit-history should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/rewrite-commit-history/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How rewrite-commit-history Compares
| Feature / Agent | rewrite-commit-history | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Rewrite a feature branch's commit history into clean conventional commits that tell a progressive, linear story. Handles backup, soft reset, and atomic recommit. Use when: (1) Cleaning up messy WIP commits before PR, (2) Reorganizing commits into logical units, (3) Converting commits to conventional commit format. Triggers on: "rewrite history", "clean up commits", "rewrite commits", "conventional commits", "squash and rewrite", "reorganize commits".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Rewrite Commit History
Rewrite a feature branch's messy commit history into clean, conventional commits that tell a progressive, linear story — safe to read, review, and bisect.
## Workflow
### Step 1 — Guard
Abort if the working tree is dirty. A clean rewrite requires a clean state.
```bash
git status --porcelain
```
If output is non-empty: stop. Tell the user to stash or commit pending changes first.
Then detect the parent branch. The entire rewrite depends on using the correct base — a wrong base means wrong diffs and wrong commits.
```bash
git log --oneline --decorate --graph --all | head -20
```
Check if the branch has commits relative to `main`:
```bash
git log --oneline main..HEAD 2>/dev/null | wc -l
```
If the count is 0 or the command fails, the branch was likely forked from something other than `main`. Ask the user to confirm the target branch before proceeding. Do not assume `main`.
Common alternatives: `master`, `develop`, `staging`, `origin/main`.
Once confirmed, set the base branch for all subsequent steps:
```bash
BASE=<confirmed-branch> # e.g. BASE=main or BASE=develop
```
### Step 2 — Backup
Create a timestamped backup branch at the current HEAD before touching anything.
```bash
BRANCH=$(git rev-parse --abbrev-ref HEAD)
EPOCH=$(date +%s)
git branch backup/${BRANCH}-${EPOCH}
```
Confirm backup was created. This is the restore point if anything goes wrong.
### Step 3 — Analyze
Read the full diff and log between the base branch and HEAD.
```bash
git log --oneline ${BASE}..HEAD
git diff --stat ${BASE}...HEAD
```
For large branches (many files), start with `--stat` to see the scope before reading the full diff. Then read individual files as needed to understand the changes in depth.
```bash
git diff ${BASE}...HEAD
```
Identify the logical units of work. Look for:
- Feature additions (new files, new functions)
- Bug fixes (targeted changes to existing code)
- Refactors (structural changes with no behavioral difference)
- Config/tooling changes
- Tests added or updated
- Docs updated
Group related changes together. A good commit is one logical unit, not one file.
### Step 4 — Plan
Present the proposed commit sequence to the user. Each entry must include:
- The conventional commit message (type + scope + subject)
- A brief summary of which files/changes are included
Order commits so each builds on the previous — the branch should compile and make sense at every point.
Example plan format:
```
1. feat(auth): add JWT token generation
Files: src/auth/token.ts, src/auth/types.ts
2. feat(auth): add login endpoint with token issuance
Files: src/routes/auth.ts, src/routes/auth.test.ts
3. chore: update env example with JWT secret
Files: .env.example
```
Before confirming, verify every file that appears in `git diff --stat ${BASE}...HEAD` is assigned to at least one commit in the plan. Unassigned files will cause the tree parity check to fail in Step 6.
### Step 5 — Confirm
Wait for user approval before executing. Accept:
- Approval as-is
- Edits to commit messages
- Reordering of commits
- Splitting one commit into two
- Merging two commits into one
Do not proceed until the user confirms the plan.
### Step 6 — Execute
Soft-reset to the merge base, then create each commit one at a time with selective staging.
```bash
git reset --soft $(git merge-base ${BASE} HEAD)
```
For each planned commit:
```bash
git add <specific files for this commit>
git commit -m "<conventional commit message>"
```
Use selective `git add` — never `git add -A` for a batch. Each commit must contain only its planned files.
After all commits, verify tree parity against the backup:
```bash
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Find the backup branch (most recent for this branch).
# sort works correctly here because the epoch timestamp is always 10 digits (valid until 2286).
BACKUP=$(git branch --list "backup/${BRANCH}-*" | sort | tail -1 | tr -d ' ')
git diff HEAD ${BACKUP}
```
If diff is non-empty: something was lost or corrupted. Restore immediately:
```bash
git reset --hard ${BACKUP}
```
Report the failure and stop.
### Step 7 — Verify
Confirm success:
- `git log --oneline ${BASE}..HEAD` shows the new clean history
- `git diff HEAD ${BACKUP}` is empty (tree parity confirmed)
- Report the backup branch name so the user can delete it when satisfied
## Conventional Commit Types
| Type | Use for |
|------|---------|
| `feat` | New feature or capability |
| `fix` | Bug fix |
| `refactor` | Code change with no behavior change |
| `test` | Adding or updating tests |
| `docs` | Documentation only |
| `chore` | Build, tooling, config, deps |
| `perf` | Performance improvement |
| `ci` | CI/CD changes |
| `style` | Formatting, whitespace (no logic change) |
| `revert` | Reverts a previous commit |
**Format**: `type(scope): subject` — subject is imperative, lowercase, no period.
**Breaking changes**: Append `!` after type/scope, e.g. `feat(api)!: rename endpoint`.
## Base Branch Override
Default base is `main`. Override with `BASE=<branch>` before running, or ask the user if uncertain.
Common alternatives: `master`, `develop`, `staging`, `origin/main`.
## Examples
### Positive Trigger
User: "Can you clean up my commits before I open this PR? It's a bunch of WIP saves."
Expected behavior: Use this skill. Start with Step 1 (guard check), then proceed through all steps.
### Positive Trigger
User: "Rewrite my commit history into conventional commits."
Expected behavior: Use this skill. Follow the full 7-step workflow.
### Non-Trigger
User: "Write a commit message for my current changes."
Expected behavior: Do not use this skill. Write a single commit message directly.
### Non-Trigger
User: "Squash my last 3 commits into one."
Expected behavior: Do not use this skill. Use `git reset --soft HEAD~3` directly and commit.
## Troubleshooting
### Working Tree Is Not Clean
- Error: `git status --porcelain` returns output before the rewrite starts.
- Cause: Unstaged or staged changes exist in the working directory.
- Solution: Ask the user to stash (`git stash`) or commit pending changes, then retry.
### Merge Base Cannot Be Found
- Error: `git merge-base ${BASE} HEAD` fails or returns unexpected output.
- Cause: The base branch name is wrong, or the branch has no common ancestor with the specified base.
- Solution: Ask the user to confirm the base branch. Try `git log --oneline` to see branch history.
### Tree Parity Check Fails After Rewrite
- Error: `git diff HEAD ${BACKUP}` is non-empty after all commits are created.
- Cause: One or more files were missed during selective staging, or a file was double-staged.
- Solution: Immediately restore with `git reset --hard ${BACKUP}`. Report which files diverged. Re-plan and retry.
### Backup Branch Not Found During Verify
- Error: `git branch --list "backup/${BRANCH}-*"` returns empty.
- Cause: Branch was deleted or the shell variable substitution failed.
- Solution: Run `git branch --list "backup/*"` to locate any backup branches. Do not proceed with verification until the backup is confirmed.Related Skills
agent-skills-manager
Manage AI skills from the Ravn AI Toolkit via corvus CLI — install, update, remove, search, and configure skills for any project. Use when: (1) Installing AI skills into a project, (2) Updating installed skills to latest versions, (3) Browsing or searching available skills, (4) Configuring global or per-project skill sets, (5) Troubleshooting corvus setup. Triggers on: "install skills", "add skills", "update skills", "corvus", "skill manager", "browse skills", "set up AI rules".
type-system-audit
Audit a repository for type-system weaknesses using recent bug-fix commits as hard evidence. Produces prioritized findings tied to specific commits showing which types allowed real bugs. Use when: reviewing type safety, auditing types, analyzing type bugs. Triggers on: type audit, type system review, audit types, type safety audit.
ts-linter
Set up and enforce a strict, production-grade ESLint configuration for TypeScript projects, then systematically fix all linting issues. Use this skill whenever the user asks to add a linter or ESLint, enforce code quality rules, fix linting errors, clean up code style, or add type-aware linting. Trigger on: "lint", "eslint", "code quality", "static analysis", "strict linting", "make it stricter", "make the code stricter", "add better rules", "clean up the codebase", "enforce standards", "fix all the warnings", or "ShadCN lint errors". Handles detection, config generation, dependency installation, auto-fix, and manual remediation. Do NOT use for Biome or Rome projects, Prettier-only formatting, non-TypeScript/JavaScript projects, writing custom ESLint rules or plugins, husky/lint-staged/pre-commit hook setup, or when the user just wants to run an existing linter without changing its configuration.
transcript-notes
Convert meeting transcript .txt files into structured .md notes with metadata, TL;DR, key topics, action items, and quotes. Use when processing raw transcripts into formatted notes. Triggers on: "process transcript", "generate notes from transcript", "transcript to notes", "/transcript-notes".
test-plan-gen
Generate professional QA Test Plan documents (.docx or .pdf) from a structured interview. Trigger on "create/write a test plan", "I need a test plan", "prepare QA documentation", /testplan, or when a user uploads a PRD/requirements and wants a test plan generated.
test-case-gen
Generate, evaluate, audit, and normalize QA test cases to RAVN standards. Trigger on "generate/write/create test cases", "evaluate/score my test cases", "audit my test suite", "review test coverage", "normalize/reformat test cases", or when a user wants test design help. Also triggered by /testcases.
tech-react
React 19 patterns for components, hooks, Server Components, and data fetching. Use when writing React components, managing state with hooks, implementing Suspense boundaries, optimizing renders with proper memoization, or building Server/Client component hierarchies.
tech-drizzle
Drizzle ORM typesafe schema design, relational queries, prepared statements, migrations, and transactions. Use when working with Drizzle ORM, writing database queries, managing migrations, or optimizing query performance with prepared statements.
tech-android
Android and Kotlin development patterns — Compose, architecture, coroutines, Room, navigation, Hilt. Use when building Android apps, writing Jetpack Compose UI, or reviewing Android-specific code.
swift-concurrency
Swift Concurrency patterns — async/await, actors, tasks, Sendable conformance. Use when writing async/await code, implementing actors, working with structured concurrency, or ensuring data race safety.
qa-personality-builder
Create custom QA agent personalities for project-specific testing needs. Guided builder that asks about the specialty, tools, and test scenarios, then generates a personality file and registers it in the QA config. Trigger on "create a QA personality", "add a custom test agent", "build a webhook tester", or when the user needs a project-specific QA agent. Also triggered by /qa-create-personality.
qa-orchestrator
Orchestrate QA agent workflows — spawn test agents in parallel, collect results, triage bugs, trigger the bug fixer, and generate QA reports. The main entry point for running a QA session. Trigger on "run QA", "start QA session", "test the PR", "orchestrate QA agents", or when the user wants to run multiple QA agents together. Also triggered by /qa-orchestrator.