Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to delete the last 2 commits from one of my GitHub repositories. I've tried as suggested here : git push -f origin HEAD^^:master. It seems that it works, as the last two commits are removed.

Then I deleted them from my local repository with git rebase -i HEAD~2. I remove the lines that are related to those commits, and check with git log that they are correctly removed.

After that, I make some changes in my local repository, make a new commit, and push to GitHub. The problem is that, in my GitHub account, I have the previous two commits that I've tried to delete.

I think the problem is in my local repository, because if I clone my Github repository to my local and make some changes here, when I push a new commit those old commits aren't pushed to GitHub.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
813 views
Welcome To Ask or Share your Answers For Others

1 Answer

To remove the last two commits locally I'd suggest using:

git reset --hard HEAD^^

Rebase is a completely different operation that won't help you here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...