Git rewriting history
Skill narenaryan/agent-skills/skills/git/git-rewriting-history
Byte-sized agent skills for giving advanced knowledge to AI agents
npx -y skills add narenaryan/agent-skills --skill git-rewriting-historyAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use when editing past commits — amending, splitting, squashing, reordering, dropping, or bulk-rewriting history with interactive rebase or filter-repo
SKILL.md
1.9 KB, 476 tokens by cl100k_base, as published. Nobody here has run it
Rewriting Git History
Iron rule: only rewrite commits not yet pushed to a shared branch. Every rewrite changes the SHA of the commit and all descendants.
Amend
git commit --amend # edit message + staged changes
git commit --amend --no-edit # fold staged changes, keep message
git commit --amend --author="Name <email>"
Interactive Rebase
git rebase -i HEAD~N
git rebase -i --root
git rebase -i --autosquash # auto-order fixup!/squash! commits
Commits appear oldest-first (replay order, opposite of git log).
| Verb | Effect |
|---|---|
pick | use as-is |
reword | keep diff, edit message |
edit | stop to amend diff/message |
squash | fold into previous, combine messages |
fixup | like squash, discard this message |
drop | remove entirely |
exec <cmd> | run cmd between commits (e.g. exec make test) |
Splitting
Mark edit, then at the stop:
git reset HEAD^
git add -p && git commit
git rebase --continue
Bulk Rewrite: filter-repo
Prefer git-filter-repo over deprecated git filter-branch.
git filter-repo --path secrets.env --invert-paths # purge file from all history
git filter-repo --path-rename old/:new/
git filter-repo --mailmap mailmap.txt # rewrite authors
git filter-repo --subdirectory-filter trunk
After rewrite: force-push with --force-with-lease.
Recovery
git rebase --abort
git reflog && git reset --hard HEAD@{N}
Pitfalls
--autosquashneeds commits made viagit commit --fixup=<sha>.exec make testbetween commits pinpoints which rewritten commit breaks the build.filter-branchsilently corrupts edge cases;filter-reporefuses unsafe rewrites.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.