↩️ UndoingCommonly used

How to undo a commit that has already been pushed

Remove or reverse a commit that has already been pushed to a remote repository.

Revert the commit (safe — adds a new commit)
git revert HEAD
git push

Creates a new commit that undoes the changes. Safe because it does not rewrite history.

When to use: Recommended for shared branches. Does not break other people's history.

Revert a specific commit
git revert abc1234
git push

Reverts a specific commit by hash. Creates a new "undo" commit.

Reset and force push (destructive)
git reset --hard HEAD~1
git push --force-with-lease

Removes the commit locally and overwrites remote history.

Rewrites shared history. Other developers will have conflicts. Only use on your own branches.

When to use: Only on branches that no one else is using.

← Back to Git Reference