Files
holocron/plugins/git/.apm/skills/git-commits/references/rewrite-history.md
Defame1297 f3b4860e14 refactor(git-commits): retrofit to the ADR-0020 context contract
Description 724 -> 214 chars, body 1102 -> 343 words, Gotchas 12 -> 3.
Create, rewrite, and cherry-pick flows move to self-contained references/
files behind a dispatch table.

The audit caught that moving the secret scan into the create flow left the
amend/squash path with no check in its loaded context; it is now a gate
common to every flow. Also re-homes the interactive-rebase reflog warning
git-history dropped, since this skill owns rebase.
2026-08-30 13:10:53 +00:00

2.1 KiB

source_keys
source_keys
org-commit-conventions
context7-git-htmldocs

Rewriting existing commits

Every flow on this page rewrites history. None of them runs before the caller has explicitly approved it, and none is followed by a force-push to main/master — refuse that and explain why instead.

Amend the last commit

  1. Stage the new changes, or the changes that undo something.
  2. Run rtk git commit --amend, adding --no-edit when the message stays as it is.
  3. If the message should change, show the current one and prompt for the replacement.
  4. The branch has now diverged from its remote. Amending is safe only on a branch nobody else has based work on; on main/master, refuse the force-push and explain, rather than warning and proceeding.

Fold a commit into an earlier one (autosquash — preferred)

Prefer this whenever a commit is written to be folded, because git does the marking:

  1. rtk git commit --fixup=<commit> keeps the target's message; rtk git commit --squash=<commit> lets you edit the combined message later. Both prefix the message with fixup!/squash! and name the target commit.
  2. Get explicit approval — the rebase still rewrites history.
  3. Run rtk git rebase --autosquash HEAD~N, or -i --autosquash to review the plan first. Git reorders the tagged commits against their targets automatically.

Squash by hand (interactive rebase)

Use this when the commits were not tagged at commit time. Interactive rebase has no undo once rebase -i starts — git reflog is the recovery path.

  1. Identify the commits to squash — typically the last N on the current branch.
  2. Get explicit approval.
  3. Run rtk git rebase -i HEAD~N, marking the older commits squash to keep their messages for editing, or fixup to discard them.
  4. Compose the combined message when the rebase stops to ask. For a non-trivial combined message, follow the structure in references/commit-template.md.

When a rebase halts on a conflict

Offer conflict resolution or rtk git rebase --abort. Do not resolve conflicts automatically without confirmation.