git commit --amend

A form of git commit that replaces the most recent commit with a new one, combining its changes with whatever is staged and optionally a new message.

In more detail

The replacement has a new ID, so amending is rewriting history: fine before you push, but once others have pulled the old commit you should make a new commit instead. Pushing an amended commit that was already pushed is rejected unless you force it.

Example

git commit --amend -m 'Add file and update'

Related terms

Taught in

References