feat: add git-history-cleanup skill for rewriting feature branch history - #20
Conversation
Greptile SummaryAdds a generated, cross-tool git-history-cleanup skill that plans and rewrites feature-branch commits, verifies tree equivalence, and pushes the rewritten history.
|
| Filename | Overview |
|---|---|
| .claude/commands/git-history-cleanup.md | Defines the destructive workflow, but the branch argument is not bound to the checkout, merge-containing rebuilds use the wrong ancestry target, and existing-branch pushes have no explicit destination. |
| tools/generate | Correctly registers the new canonical command for generation across the supported skill directories. |
| README.md | Documents the new command consistently, although its safety guarantees depend on correcting the canonical workflow. |
| .codex/skills/git-history-cleanup/SKILL.md | Generated copy faithfully propagates the canonical workflow and its branch-targeting, ancestry, and push issues. |
| .copilot/skills/git-history-cleanup/SKILL.md | Generated copy faithfully propagates the canonical workflow and its branch-targeting, ancestry, and push issues. |
| .antigravity/skills/git-history-cleanup/SKILL.md | Generated copy faithfully propagates the canonical workflow and its branch-targeting, ancestry, and push issues. |
| .kimi-code/skills/git-history-cleanup/SKILL.md | Generated copy faithfully propagates the canonical workflow and its branch-targeting, ancestry, and push issues. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Resolve requested branch and default branch] --> B{Guards pass?}
B -- No --> C[Stop without rewriting]
B -- Yes --> D[Survey commits and show rewrite plan]
D --> E[Create pre-cleanup backup]
E --> F{Rewrite strategy}
F -- Fold or reorder --> G[Non-interactive rebase]
F -- Regroup changes --> H[Soft-reset and rebuild commits]
G --> I{Tree equals backup?}
H --> I
I -- No --> J[Restore backup and stop]
I -- Yes --> K[Push rewritten branch with lease]
K --> L{Push succeeds?}
L -- No --> M[Keep backup and report failure]
L -- Yes --> N[Delete backup and report result]
Reviews (1): Last reviewed commit: "feat(git-history-cleanup): auto force-pu..." | Re-trigger Greptile
There was a problem hiding this comment.
Pull request overview
Adds a new manually invoked git-history-cleanup Agent Skill to help rewrite a feature branch’s history into clean, review-friendly commits, and wires it into the repo’s skill-generation pipeline and documentation.
Changes:
- Register
git-history-cleanupin the generator so it’s emitted for each supported harness. - Add canonical skill source at
.claude/commands/git-history-cleanup.mdand generated per-tool copies under.codex/,.copilot/,.antigravity/,.kimi-code/. - Document the new command and usage variants in
README.md.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tools/generate |
Adds git-history-cleanup to the generated skill set. |
README.md |
Documents /git-history-cleanup purpose and per-tool invocation syntax. |
.claude/commands/git-history-cleanup.md |
Canonical skill definition and workflow for rewriting branch history safely. |
.codex/skills/git-history-cleanup/SKILL.md |
Generated Codex skill copy of the canonical command. |
.copilot/skills/git-history-cleanup/SKILL.md |
Generated Copilot skill copy of the canonical command. |
.antigravity/skills/git-history-cleanup/SKILL.md |
Generated Antigravity skill copy of the canonical command. |
.kimi-code/skills/git-history-cleanup/SKILL.md |
Generated Kimi Code skill copy of the canonical command. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (3)
.claude/commands/git-history-cleanup.md:44
- Creating a fixed-name backup branch (
<branch>-pre-cleanup) can fail on re-runs (or after a previous failed cleanup) because the backup branch is explicitly kept on failure. Add an explicit instruction to stop rather than overwrite an existing backup branch name.
1. **Safety net first:** `git branch <branch>-pre-cleanup` on the current tip. It stays until the rewrite is verified and pushed — never delete it before then.
README.md:144
- This section says the command refuses to run on
main, but the actual guard logic (in the skill text) resolves the repo’s default branch fromorigin/HEAD(and falls back tomain/master). Updating this wording avoids incorrect docs in repos whose default branch isn’tmain.
Rewrite a feature branch's git history into focused, logical commits before review or merge. It surveys the branch's commits past the merge base, folds review-response, fixup, WIP, and lint-fix noise into the substantive commits they amend, and reorders the result so each commit is reviewable on its own and `git blame` stays meaningful. Refuses to run on `main` or other long-lived branches, creates a backup branch before rewriting, and verifies the final tree is byte-identical to the original tip. Once verified it force-pushes with `--force-with-lease` (never bare `--force`) and deletes the backup branch; on any failure the backup is kept so the original history is never lost.
.claude/commands/git-history-cleanup.md:2
- The frontmatter description says the command refuses to run on "main", but the guards below resolve and protect the repository’s default branch via
origin/HEAD(and fall back tomain/master). This description should align with the actual guard behavior so it’s accurate in repos whose default branch is notmain.
This issue also appears on line 44 of the same file.
description: "Rewrite a feature branch's git history into focused, logical commits by folding review-response, fixup, and WIP noise into the changes they belong to. Use when asked to clean up, squash, or tidy a branch's commits before review or merge. Refuses to run on main or other long-lived branches, works on a backup branch, verifies the final tree is identical, then force-pushes with lease and removes the backup."
- Rewrite a work branch's commits into focused, logical units, folding review-response, fixup, and WIP noise into the changes they amend - Guard against protected and shared branches and dirty worktrees, back up the original tip, verify the rewritten tree is identical, then push with --force-with-lease and drop the backup (kept on any failure) - Register the command in tools/generate and document it in README Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CXfFwcsLw7CDauvJVkVYMy
b5c21e8 to
079cbf3
Compare
Summary
Adds a new manually invoked
/git-history-cleanupcommand that rewrites a work branch's git history into focused, logical commits — folding review-response, fixup, WIP, and lint-fix noise into the substantive commits they amend — so the history is easy for reviewers to follow andgit blamepoints at commits that explain why a line exists.What the skill does
origin/HEAD),develop,staging,production, orrelease/*/hotfix/*branches; requires a clean worktree; stops when there is nothing past the merge base or the branch is already merged; warns before rewriting history containing other authors' commits.<branch>-pre-cleanupbackup branch first, then rewrites via a non-interactive rebase (GIT_SEQUENCE_EDITOR) for simple folds or a soft-reset rebuild for regrouping across commits.--force-with-lease(plain push if the branch is not on the remote) and deletes the backup branch. On a rejected lease or failed push, it stops and keeps the backup so the original history is never lost.Changes
.claude/commands/git-history-cleanup.md— canonical command sourcetools/generate— registergit-history-cleanupinSKILL_COMMANDS.codex/,.copilot/,.antigravity/,.kimi-code/skills/git-history-cleanup/SKILL.md— generated per-tool copiesREADME.md— document the new command with per-tool usageTesting
tools/generate --checkreports generated files in sync🤖 Generated with Claude Code
https://claude.ai/code/session_01CXfFwcsLw7CDauvJVkVYMy
Generated by Claude Code