↩️ UndoingCommonly used
How to undo a commit that has already been pushed
Remove or reverse a commit that has already been pushed to a remote repository.
Revert the commit (safe — adds a new commit)
git revert HEAD
git pushCreates a new commit that undoes the changes. Safe because it does not rewrite history.
When to use: Recommended for shared branches. Does not break other people's history.
Revert a specific commit
git revert abc1234
git pushReverts a specific commit by hash. Creates a new "undo" commit.
Reset and force push (destructive)
git reset --hard HEAD~1
git push --force-with-leaseRemoves the commit locally and overwrites remote history.
Rewrites shared history. Other developers will have conflicts. Only use on your own branches.
When to use: Only on branches that no one else is using.