Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to erase a published Git commit from history?

Tags:

git

github

I accidentally committed a change with Git, pushed it up to GitHub, and have done several commits afterward. I need to erase that commit from the history. I realize this could possibly hose other forks and I'm ok with that.

I was able to modify my history locally with a command like:

git rebase --onto HEAD~4 HEAD~3 HEAD

which seemed to work fine. However, I don't then know how to get that changed history pushed appropriately back to github.

like image 708
Alex Miller Avatar asked Jun 08 '11 03:06

Alex Miller


1 Answers

I managed to accomplish the whole process a different way after some messing around:

git rebase -i <commit>^
... delete first commit in editor ...
git push -f
like image 108
Alex Miller Avatar answered Sep 24 '22 03:09

Alex Miller