How do you undo a commit that has already been pushed?
If a commit has been pushed to a shared branch, the safest way is to revert it — not
remove it.
git revert <commit-hash>
This creates a new commit that undoes the changes from the old one, without rewriting
history.
Example:
If you pushed a buggy commit that broke the login page, git revert creates a new
commit that removes those buggy changes while keeping the history intact.
⚠ Avoid git reset on shared branches because it rewrites history — it can
mess up others’ work.