agentleFS
narenaryannarenaryan/agent-skills/skills/git/git-rewriting-history/SKILL.md

git-rewriting-history

Skill0 starsChanged 39 days agoMITView on GitHub

Use when editing past commits — amending, splitting, squashing, reordering, dropping, or bulk-rewriting history with interactive rebase or filter-repo

  • Reads credentials
  • Deletes or force-pushes

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Iron rule: only rewrite commits not yet pushed to a shared branch.

    line 8
  2. Very specific:

    Prefer git-filter-repo over deprecated git filter-branch.

    line 49
  3. Very specific:

    After rewrite: force-push with --force-with-lease.

    line 58

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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).

VerbEffect
pickuse as-is
rewordkeep diff, edit message
editstop to amend diff/message
squashfold into previous, combine messages
fixuplike squash, discard this message
dropremove 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

  • --autosquash needs commits made via git commit --fixup=<sha>.
  • exec make test between commits pinpoints which rewritten commit breaks the build.
  • filter-branch silently corrupts edge cases; filter-repo refuses unsafe rewrites.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.