Found a mistake three commits back? git commit --fixup fixes it in place

Instead of a "small fix" commit at the end of the branch, git commit --fixup makes a commit tied to the wrong one, and git rebase --autosquash folds it in before you open the pull request.

Published 2 min read#Developer tools#Web development

You have a branch with five tidy commits, and just before you open the pull request you find a typo in the second one. The usual fix is a sixth commit called "small fix", and the reviewer reads the mistake and its fix in two places. In this article you fix the mistake inside the commit itself.

What does git commit --fixup do?

git commit --fixup=<commit> makes a new commit whose title is fixup! followed by the title of the commit you want to fix. This commit changes the content of the old commit when it is folded into it, and leaves its message as it is.

According to the git commit docs, git rebase --autosquash recognizes this title on its own, and any extra message you add with -m is thrown away when it is folded in.

git add src/header.js
git commit --fixup=a1b2c3d

How does the fix get folded in place?

git rebase --autosquash finds every commit whose title starts with fixup!, squash! or amend!, moves it right after the commit it fixes, and folds it in.

git rebase -i --autosquash main

According to the git rebase docs, -i opens the todo list for you to review before it goes on, and if you set rebase.autoSquash to true in your config, autosquash is on by default for interactive rebase.

git config --global rebase.autoSquash true

What is the difference between fixup, amend and reword?

The three forms go after --fixup=, and the difference is what changes in the old commit:

Form

Content

Message

--fixup=<commit>

changes

stays as it is

--fixup=amend:<commit>

changes

replaced by a new message

--fixup=reword:<commit>

does not change

replaced by a new message

amend and reword make a commit whose title starts with amend!. And the docs say none of them changes the author of the original commit.

Where do you start now?

The lesson for you as a developer: the branch history is part of the review, and every fix belongs inside the commit that was wrong.

  1. Find the wrong commit with git log --oneline.

  2. Make the fix, then run git commit --fixup=<hash>.

  3. Before the pull request, run git rebase -i --autosquash against the main branch.

If the wrong commit was pushed and someone else has it, the safer way is the git revert article. If you need to find which commit broke something, see the git bisect article. And if you are building your basics as a developer, there is the 2026 developer roadmap.

The last pull request you opened: did it have a commit called "fix"?

FAQ

Does a fixup change the author of the original commit?

No. The Git docs say fixup and amend commits do not change the authorship of the original commit when they are folded into it.

Do I have to type --autosquash every time?

No. If you set rebase.autoSquash to true in your config, it is on by default for interactive rebase, and you can turn it off once with --no-autosquash.

Can I use it on a branch I pushed and share with someone?

Better not. A rebase rewrites the commits, so whoever pulled the branch finds a different history. Use it on your own branch before you merge it.

Share

More articles