git fixup + autosquash: how to clean up an AI agent's commit history before review
TL;DR: git commit --fixup=<sha> creates a fixup! <subject> commit, and git rebase -i --autosquash moves it next to the commit it fixes and squashes it in, keeping the original message. On Git 2.47.3 I folded a three-commit agent branch plus one fixup into a single clean commit in one command. Three things bite people: the fixup target must be inside the range you rebase (otherwise Git says “Successfully rebased” and silently leaves the fixup as its own commit), a conflicting fixup stops the rebase with exit code 1, and -m is rejected together with --fixup=amend:.
Everything below was run on git version 2.47.3 on a throwaway repository on November 22, 2026. The outputs are copied verbatim from that run.
What problem does git commit --fixup actually solve?
An AI coding agent (Cursor, Claude Code, Codex CLI) often leaves you a branch like this:
7a8d498 fix: guard empty input in parse
e9fff41 WIP: add parser helper
ed6a4cf feat: add health endpoint
Three commits, one of them named WIP:, and the tests for the first commit landed in a later one. If you open a pull request with that history, a human reviewer has to reconstruct which change belongs to which commit — and if the agent gets the diff wrong, every commit in the stack has to be rebased by hand.
git commit --fixup gives you a way to say “this change belongs to that commit” without rewriting anything yet:
$ git add -A
$ git commit --fixup=ed6a4cf
[main f7fef40] fixup! feat: add health endpoint
1 file changed, 4 insertions(+)
create mode 100644 tests/test_app.py
The commit is created, the working tree is clean, and nothing in the history has moved yet. Per the official git-commit documentation, a plain --fixup=<commit> “creates a ‘fixup!’ commit which changes the content of <commit> but leaves its log message untouched.”
What does git rebase --autosquash do with a fixup! commit?
git rebase --autosquash rewrites the rebase todo list before you ever see it. The git-rebase documentation says it moves each marker commit “right after the commit they modify” and changes the action from pick to squash, fixup, or fixup -C.
Here is the todo list Git generated for the branch above, captured by pointing GIT_SEQUENCE_EDITOR at a script that copies the file:
$ GIT_SEQUENCE_EDITOR=/tmp/fx/editor.sh git rebase -i --root --autosquash
Rebasing (1/4)
Rebasing (2/4)
Rebasing (3/4)
Rebasing (4/4)
Successfully rebased and updated refs/heads/main.
rebase exit=0
$ head -4 /tmp/fx/todo.txt
pick ed6a4cf feat: add health endpoint
fixup f7fef40 fixup! feat: add health endpoint
pick e9fff41 WIP: add parser helper
pick 7a8d498 fix: guard empty input in parse
Note that the fixup line is not where the commit was (it was on top) — Git moved it down to sit directly under its target. Running the rebase for real gives:
$ git log --oneline
ce39056 fix: guard empty input in parse
fe69105 WIP: add parser helper
99fff9d feat: add health endpoint
Four commits became three, and the folded commit now carries the file that the fixup added:
$ git ls-tree -r --name-only 99fff9d
editor.sh
src/app.py
tests/test_app.py
The original message survived and the fixup! subject was discarded — that is the difference between fixup and squash in the todo list: squash keeps both messages and opens an editor, fixup keeps only the earlier one.
Why did my first rebase do nothing? The target was outside the range
This is the failure mode that costs people an hour. I ran git rebase -i --autosquash HEAD~3 in that same repository, and Git reported success:
$ GIT_SEQUENCE_EDITOR=/tmp/fx/editor.sh git rebase -i --autosquash HEAD~3
Successfully rebased and updated refs/heads/main.
rebase exit=0
$ head -1 /tmp/fx/todo.txt
pick e9fff41 WIP: add parser helper
The fixup commit was still a plain pick, and the history was unchanged:
$ git log --oneline
f7fef40 fixup! feat: add health endpoint
7a8d498 fix: guard empty input in parse
e9fff41 WIP: add parser helper
ed6a4cf feat: add health endpoint
The reason is that the fixup target (ed6a4cf) was the upstream of the rebase, so it was not being rebased and could not be modified. Git matched no commit for the fixup! marker, so it left the line as a pick — no warning, no error.
The rule: the commit your fixup points at must be inside the range you are rebasing. When the target is the root commit of the branch, that means using --root:
$ git rebase -i --root --autosquash
With --root, the todo list starts at the first commit of the branch and the fixup attaches correctly. If you prefer, git rebase -i --autosquash <target>^ rebases everything from the target’s parent.
What happens when the fixup conflicts?
Sometimes the fixup touches the same lines as a later commit, and the rebase stops. Here is the real output from a repository where the fixup changed a line that a later commit had also touched:
$ GIT_SEQUENCE_EDITOR=/tmp/fxc/editor.sh git rebase -i --root --autosquash
Rebasing (1/4)
Rebasing (2/4)
Rebasing (3/4)
Auto-merging f.txt
CONFLICT (content): Merge conflict in f.txt
error: could not apply 9d1b2b7... fixup! feat: add two
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 9d1b2b7... fixup! feat: add two
rebase exit=1
The exit code is 1, and git status tells you exactly where you are:
$ git status
interactive rebase in progress; onto 37e31bf
Last commands done (3 commands done):
pick 1499f07 feat: add two
fixup 9d1b2b7 fixup! feat: add two
(see more in file .git/rebase-merge/done)
Next command to do (1 remaining command):
pick 7adb761 chore: add three
(use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'main' on '37e31bf'.
(fix conflicts and then run "git rebase --continue")
If the conflict means the fixup was wrong, git rebase --abort puts everything back exactly as it was (exit code 0, original SHAs restored). If the conflict is just a context mismatch, resolve the file, git add it, and git rebase --continue — the fixup still gets folded into its target.
How do I replace a commit message with --fixup=amend:?
Sometimes the problem is not the code but the message: the agent wrote feat: add parser for a commit that actually adds a retry policy. git commit --fixup=amend:<commit> creates an amend! commit, and per the docs it “also replaces the log message of <commit> with the log message of the ‘amend!’ commit”.
$ GIT_EDITOR=/tmp/fxf/msg-editor.sh git commit --fixup=amend=efd19e5
[main 454b87c] amend! feat: add two
1 file changed, 1 insertion(+)
create mode 100644 NOTES.md
After the autosquash, the todo line changes shape — it becomes fixup -C, which keeps the amend commit’s message:
$ head -4 /tmp/todo-dump.txt
pick 0649189 feat: start
pick efd19e5 feat: add two
fixup -C 454b87c amend! feat: add two
and the rewritten commit keeps its place in the history with the new message:
$ git log --oneline
4f7b9de feat: add two, with the uppercase value
0649189 feat: start
$ git log --format="%B" -1
feat: add two, with the uppercase value
Two traps with amend::
-mis rejected:git commit --fixup=amend:<sha> -m "new message"fails withfatal: options '-m' and '--fixup:amend' cannot be used together. The message is written in the editor that Git opens, with theamend!prefix pre-filled.- Do not delete the
amend!prefix. If your editor rewrite drops that first line, Git no longer recognises the commit as a marker commit, the todo line stayspick, and your reworded message silently becomes a separate commit instead of replacing the target’s.
--fixup=reword:<commit> is the shorthand for a message-only amend!: the documentation describes it as “shorthand for --fixup=amend:<commit> --only”, and it “replaces the log message of <commit> without making any other changes”.
Which marker should I use?
| You want | Command | Todo line it produces | Message kept |
|---|---|---|---|
| Fold a code change into an earlier commit | git commit --fixup=<sha> | fixup | the target’s |
| Fold a code change and keep both messages | git commit --squash=<sha> | squash | both, editor opens |
| Replace an earlier commit’s message | git commit --fixup=amend:<sha> | fixup -C | the new one |
| Replace a message only, no code | git commit --fixup=reword:<sha> | fixup -C | the new one |
| Fold the last two commits, no marker needed | git reset --soft HEAD~2 && git commit -m "..." | n/a | whatever you type |
The --squash option deserves a note: the git-commit documentation says the squash! marker is built from the target commit’s title, and the git-rebase documentation lists squash, fixup and fixup -C as the three actions autosquash can generate.
How do I make autosquash the default?
Set it once per repository:
$ git config rebase.autosquash true
$ git config --get rebase.autosquash
true
From then on a plain git rebase -i behaves as if --autosquash was passed:
$ GIT_SEQUENCE_EDITOR=/tmp/fxf/editor.sh git rebase -i --root
Rebasing (1/3)
Rebasing (2/3)
Rebasing (3/3)
Successfully rebased and updated refs/heads/main.
rebase exit=0
$ head -3 /tmp/todo-dump.txt
pick 0649189 feat: start
fixup 000f680 fixup! feat: start
Before you start, you can check whether any marker commits are still lying around:
$ git log --oneline --grep "^fixup!"
Empty output means there is nothing left to fold. If a fixup! commit survives a rebase, it is almost always the “target outside the range” case described above.
What does autosquash not fix?
Autosquash rewrites history, so it changes every commit SHA after the rewritten one. On a branch other people have pulled, that means a force-push and a re-review for them. Use it on your own branch before opening the pull request — not on main.
It also does not make the agent’s diff correct. If the agent produced a bad change, folding it into another commit just hides it; the same diff still lands in the pull request. And it does not change what the agent will do next run: an agent that commits WIP: add parser helper will do it again unless you add a rule. If your agent supports custom commit instructions — Codex CLI’s AGENTS.md, Claude Code’s CLAUDE.md, or Cursor’s rules — the durable fix is a rule like “one logical change per commit, conventional-commit prefixes, no WIP: subjects”, plus this command as the cleanup step.
For a cost view: a 20-commit agent branch that a reviewer has to read commit by commit is a 20-commit review. One squashed commit with a good message is a one-commit review. That is the entire value of the workflow, and it is why the two-minute command is worth doing every time.
Honest take
git commit --fixup plus git rebase -i --autosquash is the least-known, highest-value command pair in Git for people who review agent-generated branches. It takes two commands and about thirty seconds, it needs no editor skills, and it produces a pull request that a human can actually read.
Two warnings. First, the silent failure: if your fixup target is not in the rebase range, Git rewrites nothing and tells you it succeeded — always check git log --oneline after the rebase, not just the exit code. Second, git rebase --autosquash rewrites SHAs, so never run it on a shared branch.
If you want the surrounding toolkit for agent workflows, we have written up the pieces that usually come next: how to recover a branch an agent deleted, how to record conflict resolutions with rerere, how to read a rewritten history with range-diff, and how to bisect a regression an agent introduced.
Sources
- git-commit —
--fixup[=(amend|reword):]<commit>,--squash=<commit>, and the rule that neither “fixup!” nor “amend!” commits change the authorship of the target — git-scm.com - git-rebase —
--autosquash,--root, and the list of options that are incompatible with--autosquash— git-scm.com - git-config —
rebase.autosquash— git-scm.com - git-rebase — the todo list commands (
pick,reword,edit,squash,fixup,exec,drop) — git-scm.com - git-branch — how branches are held by worktrees, if you are cleaning up agent worktrees as well
- Git 2.47.3 — the version every command and output above was produced on, 2026-11-22
Last updated November 22, 2026. Every command, output, exit code and file listing above was produced by running git 2.47.3 on a throwaway repository on November 22, 2026. Git’s behaviour can change between releases — re-run the commands on your own branch before you rely on them.
Was this article helpful?
Thanks for the feedback — it helps improve future articles.
Need hands-on help?
I offer 1-on-1 technical consulting for local AI setup, GPU selection, and AI coding tool configuration — same topics covered on this site.
Book a session — $49 / hour →Know which coding tool is worth paying for
Hands-on comparisons of AI coding assistants and what each one costs to run — including the local-model path. Sent only when something changes. Unsubscribe anytime.