Last active
January 1, 2018 04:15
-
-
Save clayball/91e0cc7ac4f951a992305b2fa67d31ec to your computer and use it in GitHub Desktop.
Undo the last commit that was pushed to origin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Undo the last commit that was pushed to origin | |
| I tend to use this in conjunction with creating a new branch, GOTO 30 | |
| WARNING: git reset --hard WILL DELETE YOUR WORKING DIRECTORY CHANGES. | |
| Be sure to stash any local changes you want to keep before running these commands | |
| $ git reset --hard HEAD~1 | |
| HEAD~1 means the commit before head. | |
| If you want to go back more than one commit.. | |
| - look at the output of git log | |
| - find the commit id of the commit you want to revert back to | |
| - specify the sha1 commit id when doing the git reset, for example.. | |
| $ git reset --hard <sha1-commit-id> | |
| Because the commit was pushed to origin, we need to do a force push to get rid of the commit | |
| $ git push origin HEAD --force | |
| Create a branch based on the last commit, i.e. HEAD, then revert to previous commit and push | |
| $ git checkout -b featureX | |
| $ git checkout master | |
| $ git reset --hard HEAD~1 | |
| $ git push origin HEAD --force | |
| Work can now continue on featureX and the last commit on the master branch was removed. |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified