/git-history:git-historyfrom git-history
Edits and repairs Git history safely without opening an editor: fixup and autosquash, rebasing onto the default branch or a new base, splitting commits, cherry-pick backports, bisect, and reflog recovery. Use when asked to squash or reorder commits, update a branch with main, backport a fix, find a regression, or undo a bad rebase or reset.
Ships in git-history. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Rewriting history replaces commits with new ones. That is safe on a private branch and harmful on a shared one, so decide which case you are in before running anything. Creating commits and naming branches belong to git-commit.
git branch --remotes --contains <oldest-commit> and git rev-list --count @{u}..HEAD. Never rewrite the default branch, a release branch, or anything others may have pulled. Use git revert there.git status reports it, or test for .git/rebase-merge, .git/rebase-apply, .git/MERGE_HEAD, .git/CHERRY_PICK_HEAD and .git/BISECT_LOG (use git rev-parse --git-path <name> so worktrees resolve). If one exists, show its state and ask whether to continue or abort. Never start a second one.git reset --hard to finish or undo a rewrite; restore through a backup or rescue branch instead. If the user explicitly asks for a hard reset, first show what it discards (git status --short, git log --oneline <target>..HEAD) and get approval.git push --force-with-lease=<branch>:<expected-sha> with the sha you last saw on the remote, never bare --force. The lease fails if the remote moved, which is the point.git clean, git checkout -- <path> or git restore over changes, git branch -D, any force push, git reflog expire, git gc --prune, and a rebase that rewrites already-pushed commits.rerere/zdiff3 offer below, once the user approves it.git status --short --branch. A rebase needs a clean tree (see the stash rule above).main or master: git symbolic-ref --short refs/remotes/origin/HEAD, else git ls-remote --symref origin HEAD, else git remote show origin. Prefer the current branch's configured upstream remote over origin. If it is still ambiguous, ask.git branch backup/<branch>-<YYYYMMDD>. Tell the user its name. Delete it only when they confirm the result is good.git branch --show-current) is not the default branch. Never rebase the default branch itself.git fetch <remote> <default>, and confirm <remote>/<default> exists. Never rebase onto a local main that may be stale.git rebase <remote>/<default>. Sync often during long work, not only at the end. For a lockfile conflict, take either side and regenerate it with the package manager rather than editing markers.If the branch is shared or the user prefers merges, git merge <remote>/<default> integrates without rewriting.
When the user rebases repeatedly or hits the same conflict again, offer git config rerere.enabled true and git config merge.conflictStyle zdiff3. Ask with AskUserQuestion first; never set them silently.
The agent-safe way to amend an earlier commit is a fixup commit, then an autosquash rebase with the todo list auto-accepted.
git add <paths>
git commit --fixup=<target-sha> # creates "fixup! <target subject>"
GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash <base>
GIT_SEQUENCE_EDITOR=true runs true as the editor, so Git accepts the generated todo list; --autosquash has already moved each fixup! under its target.<base> is the commit before the oldest one you touch, often $(git merge-base HEAD <remote>/<default>).git reset --soft <base> && git commit with approval, since it discards the individual commits.git commit --amend -m "<message>". For an older commit, set GIT_SEQUENCE_EDITOR to a sed that changes its pick <short-sha> line to reword <short-sha>, and GIT_EDITOR="cp /path/to/msg" to supply the prepared message. The todo uses abbreviated shas, so match git rev-parse --short <sha>. On macOS sed -i needs '' after it.git add them, then GIT_EDITOR=true git rebase --continue. git rebase --abort returns to the start. Don't --skip a commit without telling the user which one is dropped, and never discard work to force completion.GIT_SEQUENCE_EDITOR="sed -i -e 's/^pick <short-sha>/edit <short-sha>/'" git rebase -i <sha>^
git reset HEAD^ # mixed reset: the commit's changes stay in the tree
git add <paths-a> && git commit -m "<first message>"
git add <paths-b> && git commit -m "<second message>"
GIT_EDITOR=true git rebase --continue
Confirm the tree is clean before --continue; anything left unstaged is carried forward, not lost.
git rebase --onto <new-base> <old-base> <branch>
<old-base> is the commit your branch currently forks from. Use this to move a branch off a merged parent or lift a sub-branch out of a stack. When the parent branch was squash-merged, git rebase --onto <default> <old-parent-tip> <branch> drops the parent's already-landed commits, which would otherwise show as false conflicts. Add --update-refs when branches stacked on this one should move with it. Check with git log --oneline <new-base>..<branch> and git range-diff <old-tip>...<branch>.
git cherry-pick -x <sha> # -x records the source commit in the message
git cherry-pick -x <first>^..<last> # inclusive range, oldest first
git cherry-pick -n <sha> # apply to the tree without committing
git cherry-pick --abort # leave a conflicted pick without changes
-x for backports so the origin stays traceable. Cherry-pick onto a branch made for the backport, not onto the release branch directly, unless told otherwise. For a merge commit, pass -m 1.git restore --source=<sha> -- <paths>, then commit with a message naming the source sha.Read references/recovery-and-bisect.md for git bisect run and its exit-code rules, reflog recovery, and undoing a bad rebase, reset, merge, or dropped stash.
Don't rewrite. git revert <sha> adds an inverting commit, and git revert -m 1 <merge-sha> reverts a merge. Say why in the message. If a secret was pushed, rotating it is the fix, because rewriting history doesn't remove copies others already fetched.
List the backup ref, the commands run, the before and after git log --oneline, and anything still needing approval, such as a force push.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub adminhead/claude-plugins --plugin git-history