↩️ UndoingCommonly used
How to amend the last commit in Git
Fix the last commit message or add forgotten files.
Fix the commit message
git commit --amend -m "correct message here"Replaces the last commit message with a new one. The commit hash will change.
When to use: You made a typo or wrote a poor commit message.
Add forgotten files to last commit
git add forgotten-file.txt
git commit --amend --no-editStages the forgotten file and adds it to the last commit without changing the message.
When to use: You forgot to include a file in the last commit.
Amend and open editor for message
git commit --amendOpens your editor to rewrite the commit message and shows what is staged.