How to remove published Git commit from history?

I accidentally made a change using Git, pushed it to GitHub and after that made a few commits. I need to remove this commit from the story. I understand that this can lead to other forks, and I'm fine with that.

I managed to change my story locally with a command, for example:

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

which seemed to work fine. However, I do not know how to get this modified story returned back to github.

+6
source share
2 answers

If you have any merges, you need to save them with

 git rebase -i --preserve-merges commit^ 

Otherwise, git will smooth your story.

Then click with the force parameter.

+3
source

I managed to complete the whole process differently after some involvement:

 git rebase -i <commit>^ ... delete first commit in editor ... git push -f 
+4
source

Source: https://habr.com/ru/post/890013/


All Articles