Help, I made a typo in my last commit message
Fix the message of your last commit with one command, and know when it is safe to push the change.
The fix
git commit --amend -m "Fix login redirect"Replaces the last commit with a copy that has the new message. Anything you staged goes in too, so check
git statusfirst.
Fix login redirect is an example. Replace it with your own.
git commit --amend -m "Fix login redirect"Same fix as before pushing: a corrected copy of the commit.
git push --force-with-lease --force-if-includesOverwrites the remote branch, but refuses if a teammate pushed something you have not seen. Only on your own branch: on a shared branch, live with the typo.
Rewrites pushed history
Fix login redirect is an example. Replace it with your own.
git commit --amend -m "Fix login redirect"Why this works
Commits cannot be edited, so --amend builds a new commit with the same changes and your new message and puts it where the old one was. That is why the hash changes. If nobody has the old commit yet, nobody notices. If you already pushed it, the remote still has the old one, which is why you need a force push, and why you should only do that on a branch nobody else works on.