Note Revert creates a NEW commit that undoes the changes from the specified commit. Unlike reset, it doesn't rewrite history, making it safe for shared/public branches. Always prefer revert over reset for pushed commits.
# The safe way - create a new commit that reverses the changes:git revert a1b2c3d
git push origin main
# If you need to undo multiple commits:git revert a1b2c3d..f4e5d6agit push origin main
Note NEVER use git reset + force push on a shared branch. Use git revert instead, which creates a new commit that undoes the changes while preserving history. Everyone who pulled the original commit won't have conflicts.
Frequently asked questions
How do you undo pushed commit?
Git covers this with 2 copy-ready snippets on this page. The "Revert a Commit (Safe Undo)" snippet in Git uses `git revert <commit>`.
Which command does the Git example use?
The "Revert a Commit (Safe Undo)" snippet uses `git revert <commit>`, from the Undoing Changes section of the Git cheat sheet.
What other Git snippets are shown for "undo pushed commit"?
Besides "Revert a Commit (Safe Undo)", this page also shows "Undo a Commit That's Already Pushed".
Is there anything to watch out for?
Yes. For "Revert a Commit (Safe Undo)": Revert creates a NEW commit that undoes the changes from the specified commit. Unlike reset, it doesn't rewrite history, making it safe for shared/public branches. Always prefer revert over reset for pushed commits.