Da Anonimo (non verificato) , 29 Aprile 2026

Cosa fa amend

git commit --amend sostituisce il commit piu recente con uno nuovo che include qualsiasi cosa attualmente in stage, piu un messaggio nuovo opzionale.

Tre scenari comuni di amend

# 1. Fix a typo in the last commit message
git commit --amend -m "Fix avatar upload race condition"

# 2. Add forgotten files to the last commit
git add forgotten-file.js
git commit --amend --no-edit

# 3. Replace the staged changes entirely
git add -A
git commit --amend

La regola di sicurezza

Mai modificare commit gia pushati. L'amend riscrive la storia.

# SAFE: only you have this commit
git commit --amend

# DANGEROUS: commit is on origin
git commit --amend
git push --force

Force-with-lease per branch personali

git commit --amend
git push --force-with-lease

Recuperare da un amend cattivo

git reflog
git reset --hard HEAD@{1}

Amend versus fixup

git commit --fixup <sha-to-fix>
git rebase -i --autosquash <sha-to-fix>^

Date dell'autore

git commit --amend --reset-author --no-edit