--- name: fixup description: Create a fixup commit and autosquash rebase --- # Fixup Read `../git-workflow/SKILL.md` (relative to this skill's base directory) first if it is not loaded. ## 1. Assess state Run `git status` and `git fetch origin`, detect the default branch (`git symbolic-ref refs/remotes/origin/HEAD --short`; if unset, run `git remote set-head origin --auto` first), and list commits (`git log ..HEAD --oneline`). Stop and inform the user on the default branch or a detached HEAD — never rewrite history with nowhere to land it. If the branch has an upstream and `git log HEAD..@{u}` is non-empty, stop and run `/sync` first. ## 2. Identify target - One commit on the branch → the target is HEAD. - Multiple commits → match the current changes against each commit's diff. If no target is identifiable: for a new independent change, invoke `/commit`; for history needing consolidation, invoke `/squash`, then re-run `/fixup`. - If `git config branch..gh-merge-base` names a parent and `git merge-base --is-ancestor ` succeeds, stop: the target belongs to the parent, so fix it there. ## 3. Fixup and rebase Stop first if `git log --merges ~1..HEAD` is non-empty: autosquash rebase drops merge commits, so the `fixup!` commit is left standing as a separate commit while the rebase still exits 0. Say so and let the user rebase manually. `git add `, then `git commit --fixup=`, then `GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash ~1` — before git 2.44, `--autosquash` without `-i` is silently ignored. Confirm no `fixup!` or `amend!` commit remains in `git log ..HEAD`. `git add` does not clear paths already staged, and `--fixup` commits everything in the index. Between the two, confirm with `git diff --cached --name-only` that the index holds only the files that constitute the fix; if anything else is there, stop and ask the user to commit or unstage it. After verification commands, remove side-effect files (lockfiles, caches, generated outputs) and check `git status` so artifacts do not slip into PR scope. ## 4. Message review Find the target's post-rebase hash in `git log ..HEAD`, run `git show `, and read `../commit/commit-message.md` (relative to this skill's base directory), especially "After /fixup". Evaluate whether the existing message still describes the final diff as a single coherent unit — it often does; leave it alone if so. Only if it doesn't: redraft the whole message from the final diff, never by appending to the old one, no longer than a fresh commit of that diff would need. Write it to a file, and run `/../commit/scripts/validate-message.sh ` from your working directory, with `` replaced by this skill's base directory, until it passes. If the target is HEAD, `git commit --amend -F `. Otherwise `git commit --allow-empty --fixup=reword:` — keep the prepared `amend!` first line and put the new message below it — then rerun `GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash ~1` and confirm no `amend!` commit remains. ## 5. Wrap up Show `git log ..HEAD --oneline` and suggest pushing (`git push --force-with-lease` if the target commit was already on the remote).