Skip to content
The three trees

Amending

Replacing the last commit rather than editing it.

`git commit --amend` does not modify a commit. Commits are immutable — their id is a hash of their contents, so changing one would change its name. Amend builds a new commit from the current index and moves the branch to it.

The commit you replaced is still in the object store, unreferenced, and the reflog still names it. That is what makes an unwanted amend recoverable.

Because the id changes, amending a commit you have already pushed means the remote and you now disagree — which is the whole of the force-push problem, met early.

Commands in this lesson

git commit --amend
Replace the last commit with a new one built from the index
No account, no backend. Everything you do stays in this browser.liter8.sh