How do you undo a pushed commit in Git?
It depends on who may have already taken your commit.
- Shared branch (like main): use
git revert <commit>and thengit push. History is not rewritten, so it is safe for everyone. - Your own branch, nobody else uses it: you can use
git reset --hard HEAD~1and thengit push --force-with-lease.
git revert HEAD
git push
# only on your own private branch
git reset --hard HEAD~1
git push --force-with-lease
See Git Revert and Git Push.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |