Git: Amend Last Commit
Use the --amend flag to modify the most recent commit message. This command is useful for fixing typos or adding changes you forgot to include in the last commit.
| Command | Description |
|---|---|
git commit --amend | Opens your text editor to allow you to edit the commit message. |
git commit --amend -m "New commit title" | Directly changes the last commit message without opening an editor. |
⚠️ If You Already Pushed:
If you have already pushed your changes, you'll need to force-push after amending the commit:
If you have already pushed your changes, you'll need to force-push after amending the commit:
git push --forceUse this command with extreme caution, especially on shared branches, as it rewrites history.