开发者

How to erase a published Git commit from history?

开发者 https://www.devze.com 2023-03-11 14:23 出处:网络
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

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 h开发者_JAVA百科istory pushed appropriately back to github.


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


If you have any merges you need to conserve them with

git rebase -i --preserve-merges commit^

Otherwise, git will flatten your history.

Then push with the force option.

0

精彩评论

暂无评论...
验证码 换一张
取 消