Undo a commit you already pushed
Safe: nothing is lost
Short answer
Run git revert --no-edit <commit> and push. Git adds a new commit that undoes it, so nobody's history breaks.
The commands, one by one
- 1
git revert --no-edit HEADMakes a new commit that does the exact opposite of the latest one (
HEAD).--no-editaccepts git's message, Revert "…". - 2
git pushShares the undo. Everyone gets it with their next pull.
For your own repository: For an older commit, give its hash from git log --oneline instead of HEAD.