开发者

How to erase a published Git commit from history?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜