Skip to content

Instantly share code, notes, and snippets.

@jbialy
Last active October 19, 2017 15:10
Show Gist options
  • Save jbialy/375e6bdec3e6e6814f87d10725fee38a to your computer and use it in GitHub Desktop.
Save jbialy/375e6bdec3e6e6814f87d10725fee38a to your computer and use it in GitHub Desktop.
Undo pushed commits in git...
git revert <SHA>
git push
This is Git's safest, most basic "undo" scenario, because it doesn't alter history—so you can now git push the new "inverse" commit to undo your mistaken commit.
git reset <last good SHA> or git reset --hard <last good SHA>
git push -f
git reset rewinds your repository's history all the way back to the specified SHA. It's as if those commits never happened. By default, git reset preserves the working directory. The commits are gone, but the contents are still on disk. This is the safest option, but often, you'll want to "undo" the commits and the changes in one move—that's what --hard does
reference: https://github.com/blog/2019-how-to-undo-almost-anything-with-git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment