C.W.K.
Stream
Lesson 01 of 05 · published

amend, fixup, and autosquash

~22 min · amend, fixup

Level 0Untracked Rookie
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Polish before publishing — amend, fixup, autosquash

Real coding is messy. You commit the feature, then notice a typo in a comment, then realize you forgot to update one test, then remember the docstring needs a tweak. Pushing four commits like that is noisy. The professional answer is to clean up the local history before push, so what lands on main reads as one coherent story per concern. Three commands do this work: --amend, --fixup, and --autosquash.

git commit --amend replaces the most recent commit with a new commit that combines the previous changes plus whatever is staged now. The original commit's hash is gone; the new commit takes its place. Use this for the typical "I forgot to add this file" or "the message should say X" cases. The amend opens an editor for the message; --no-edit reuses the existing message untouched.

git commit --fixup <hash> creates a new commit marked as "this should fold into commit <hash> later." It is a regular commit you can push, but it carries metadata saying it's a delayed amend. The companion git rebase -i --autosquash reads those markers and arranges the interactive rebase so each fixup commit is squashed into its target — no manual reorder, no message rewrite. git config --global rebase.autosquash true makes this automatic on every interactive rebase.

The flow that makes this hum: as you work, every "oh and also" change becomes a git commit --fixup against the original commit. You push these freely. Before merging or after review, you run git rebase -i --autosquash main and Git assembles the cleaned-up history. The PR's pre-review noisy commits collapse into the intended logical units. Reviewers see the clean version; main never sees the noise.

Code

Amend the most recent commit·bash
# Forgot to stage a file:
git add forgotten-test.js
git commit --amend --no-edit          # add to last commit, keep message

# Need to fix the message:
git commit --amend                    # opens editor

# Combined (add file AND rewrite message):
git add forgotten-test.js
git commit --amend                    # editor opens with old message
Fixup + autosquash workflow·bash
# Earlier commit you want to amend has hash abc1234.
# Stage the corrective change:
git add src/auth.js
git commit --fixup abc1234
# This creates a commit titled "fixup! &lt;original subject&gt;"

# Later, before merge or review:
git rebase -i --autosquash main
# Git reorders fixup commits next to their targets and pre-marks them for squash.
# Save and exit; the autosquash rolls them in.

# One-time global setup so autosquash is the default:
git config --global rebase.autosquash true

External links

Exercise

On a scratch branch, make three commits with intentional small problems (typo in message, missing file, etc.). Fix the most recent with git commit --amend. For an older one, create a corrective change with git commit --fixup <hash>. Run git rebase -i --autosquash main and observe how Git pre-arranges the rebase. Confirm with git log that the published-shape history shows the cleaned-up version.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.