agentleFS
mikejhillmikejhill/agent-skills/skills/git-history/SKILL.md

git-history

Skill0 starsChanged 3 days agoMITView on GitHub

Rewrite git history safely without an interactive editor: fixup commits, autosquash, interactive rebase (reword, edit, split, squash, drop), amend, and force-push. Use when changing commits that already exist.

  • Deletes or force-pushes
  • Commits and pushes

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 5 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Before any rebase, show the proposed changes (which commits are reordered, squashed, dropped, or reworded) and get the user's confirmation.

    line 25
  2. Very specific:

    Never open an editor. Interactive editors are unavailable to agents.

    line 26
  3. Very specific:

    Use --autostash on rebases when the working tree is dirty.

    line 27
  4. Very specific:

    If the commits were already pushed, follow *Force-push* below.

    line 29
  5. Distinctive:

    If anything goes wrong mid-rebase, git rebase --abort restores the original state.

    line 30
  6. Distinctive:

    Before rewriting, resolve the push destination and pin its tip once:

    line 34
  7. Very specific:

    If remote or ref is empty, or the push remote differs from the upstream remote (%(upstream:remotename)), ask the user which remote and …

    line 46
  8. Very specific:

    If the ancestry check fails, stop: the remote has commits HEAD lacks.

    line 47
  9. Very specific:

    Write the printed remote, ref, and lease into your notes.

    line 48
  10. Distinctive:

    After the rewrite, explain that a force-push is needed and collaborators must reset.

    line 50
  11. Very specific:

    Before Git 2.44, --autosquash needs -i: run GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash <oldest-target>~1.

    line 66
  12. Very specific:

    Start: git rebase -i --autostash <target-hash>~1.

    line 71
  13. Distinctive:

    After each stop, git rebase --continue.

    line 82

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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

Git history

Change existing commits with predictable, non-interactive commands, and confirm before anything that affects a shared branch.

Pick the operation

NeedOperation
Add a small forgotten change to an earlier commitFixup + autosquash
Change the last commit onlygit commit --amend
Reword a message, split, reorder, squash, or drop commitsInteractive rebase
A separate logical changeA new commit, not a rewrite

Rules

  • Show git log --oneline -n 10, name the target commit by hash and subject, and ask when it is ambiguous.
  • Before any rebase, show the proposed changes (which commits are reordered, squashed, dropped, or reworded) and get the user's confirmation.
  • Never open an editor. Interactive editors are unavailable to agents. Set GIT_SEQUENCE_EDITOR and edit the todo file directly (rebase-editor.md). Never use --edit-todo.
  • Use --autostash on rebases when the working tree is dirty.
  • New or reworded messages follow the repository's commit conventions.
  • If the commits were already pushed, follow Force-push below. Never use --force or a bare --force-with-lease, which trusts a remote-tracking ref that a background fetch can move.
  • If anything goes wrong mid-rebase, git rebase --abort restores the original state.

Force-push

Before rewriting, resolve the push destination and pin its tip once:

b="refs/heads/$(git symbolic-ref --short HEAD)"
remote=$(git for-each-ref --format='%(push:remotename)' "$b")
ref=$(git for-each-ref --format='%(push:remoteref)' "$b")
[ -n "$ref" ] || ref=$(git for-each-ref --format='%(upstream:remoteref)' "$b")   # push.default simple/upstream
git fetch "$remote" "$ref"
lease=$(git rev-parse FETCH_HEAD)
git merge-base --is-ancestor "$lease" HEAD && echo "remote=$remote ref=$ref lease=$lease"
  • If remote or ref is empty, or the push remote differs from the upstream remote (%(upstream:remotename)), ask the user which remote and branch the commits were pushed to.
  • If the ancestry check fails, stop: the remote has commits HEAD lacks. Integrate them, then run the block again.
  • Write the printed remote, ref, and lease into your notes; later commands may run in a fresh shell. Use those exact values, never a re-read FETCH_HEAD.

After the rewrite, explain that a force-push is needed and collaborators must reset. With the user's explicit yes:

git push --force-with-lease="<ref>:<lease>" <remote> "HEAD:<ref>"

Fixup and autosquash

git add <files>                          # or git add -p <file>
git commit --fixup=<target-hash>         # creates "fixup! <target subject>"
git rebase --autosquash <oldest-target>~1   # Git 2.44+; runs without stopping
git log --oneline -n 5                   # fixup commits are gone
git show <new-target-hash>               # target holds both changes

Before Git 2.44, --autosquash needs -i: run GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash <oldest-target>~1. Several fixups for different targets apply in one autosquash rebase from the oldest target. A fixup carries changes only. To change a message, use a rebase edit stop.

Interactive rebase

  1. Set the sequence editor so the rebase stops before the first commit (rebase-editor.md).
  2. Start: git rebase -i --autostash <target-hash>~1. Expect Stopped at ... from the inserted break.
  3. Edit .git/rebase-merge/git-rebase-todo (in a worktree, $(git rev-parse --git-path rebase-merge/git-rebase-todo)): change pick to edit, fixup, or drop, or reorder lines. To reword, use edit: reword opens GIT_EDITOR, which an agent cannot drive.
  4. git rebase --continue, then handle each stop:
ActionAt the stop
edit, rewordgit commit --amend -m "<message>"
edit, add filesgit add <files>, git commit --amend --no-edit, check with git show --stat
edit, fix contentChange files, git add, git commit --amend --no-edit, check with git show
edit, splitgit reset HEAD~1, then commit each part with git add -p

After each stop, git rebase --continue.

Then show the new git log --oneline and mark which commits changed. Confirm with the user before pushing.

References

  • rebase-editor.md: read before any interactive rebase. It has the sequence-editor setup for Bash and PowerShell.
  • troubleshooting.md: read on conflicts, a fixup aimed at the wrong commit, or a stuck rebase.

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.