I have checked in code into my local master git repo and then pushed it up to origin. There is only 1 such erroneous checkin. What is the best way to revert the last commit locally and remotely?
I'd prefer to destroy the history.
I have checked in code into my local master git repo and then pushed it up to origin. There is only 1 such erroneous checkin. What is the best way to revert the last commit locally and remotely?
I'd prefer to destroy the history.
If you are sure nobody has done a fetch/pull from the repo since you made the commit, do:
git reset --hard HEAD~1
git push -f
If someone has already fetched/pulled, however, there is not much you can do without their cooperation. In that case, your best bet is doing a git revert HEAD
, which will make an additional commit that undoes your last commit.
You can rewrite history to remove that commit by using git rebase -i <any earlier commit>
.
If it's the most recent commit, you can also just run git reset --hard HEAD^
.
You can then run git push -f
to rewrite the remote history. This will break anyone who pulled that commit.