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
- rewriting history — Replacing existing commits with new ones, for example with amend, rebase or reset, which gives them new IDs.
- git commit — The command that records the staging area as a new commit whose parent is the current commit, then moves the current branch to it.
- --force-with-lease — A safer force push that only overwrites the remote branch if it still points where your remote-tracking branch says it does.
Taught in
- Committing, And What A Good Message Says — Advanced Git Internals & Distributed Workflows
- Amend, And The One Hard Rule — Advanced Git Internals & Distributed Workflows