How do you undo a commit that you already pushed to a shared branch?
Use git revert, which adds a new commit that cancels the bad one. History is not rewritten, so teammates can pull normally. Avoid reset plus force-push on shared branches.
Explain it simply
Once a bad commit is on the shared branch, others may already have it. Erasing it would be like tearing a page from a notebook everyone photocopied. A revert is writing a correction on the next page.
git revert <hash> builds a new commit containing the opposite changes. History remains truthful and a normal push is enough. To undo a merge commit use -m 1 to say which parent is the mainline. If you revert a faulty merge and later want the branch back, you must revert the revert first.
Example
git revert 7f3a9d2
git push origin main
# reverting a merge commit
git revert -m 1 c91e0b4What to say in the interview
"On a shared branch I use git revert, which creates a new commit undoing the change without rewriting history. Reset with force-push would disturb everyone who already pulled. For merge commits I add -m 1 to choose the mainline parent."