The git commit --amend command allows you to modify the most recent commit. It helps fix small mistakes like incorrect commit messages or missing files without creating an additional commit.
// Opens editor to modify the last commit message
git commit --amend
// Keeps content same but allows message update
git commit --amend --no-edit
// Stage missing file before amending
git add file-name
// Adds staged changes to last commit
git commit --amend --no-edit
Git creates a brand-new commit with a different SHA-1 hash. The old commit is replaced, which means commit history changes.
Think of amend as replacing the top card in a stack instead of adding a new one.
HEAD → New Commit
// Force push updated commit to remote
git push --force
--no-edit behavior