Made a mistake in your most recent commit? Haven't yet pushed your changes? No problem!
Stage your changes:
Update your most recent commit.
This essentially re-writes your most recent commit. If your changes are minor enough to not warrant any to the commit message you can use:
git commit --amend --no-edit
Nicely fixed! 😎
I already pushed my changes...
Option 1:
Live with it... Mistakes happen, git is meant to represent the history, your history is complicated!
Option 2:
Push force:
git push --force-with-lease
The --force-with-lease
flag tells git to abandon the force push if someone else has pushed commits to the branch. Failing to use this might mean that you overwrite someone else's contributions!