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.
2.1 KiB
2.1 KiB
source_keys
| source_keys | ||
|---|---|---|
|
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
- Stage the new changes, or the changes that undo something.
- Run
rtk git commit --amend, adding--no-editwhen the message stays as it is. - If the message should change, show the current one and prompt for the replacement.
- 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:
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 withfixup!/squash!and name the target commit.- Get explicit approval — the rebase still rewrites history.
- Run
rtk git rebase --autosquash HEAD~N, or-i --autosquashto 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.
- Identify the commits to squash — typically the last N on the current branch.
- Get explicit approval.
- Run
rtk git rebase -i HEAD~N, marking the older commitssquashto keep their messages for editing, orfixupto discard them. - 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.