Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git delete pushed commits

Tags:

git

github

I am using git repository in my project. I have accidentally pushed 2 commits which I shouldn't have. And in between some one has committed on top of it. Is it possible to remove my pushed commits or I have to remove my code changes and push it as new commit, since some one has committed on top of it.

Git Master branch :

Commit A // by me

Commit B // by me

Commit C // by some one

Now I have to delete Commit A and B leaving Commit C. Any help will be really appreciated.

like image 347
Lolly Avatar asked Nov 27 '12 04:11

Lolly


1 Answers

git reset --hard HEAD~1

Where HEAD~1 means the commit before head.

Alternatively find the commit id of the commit you want (look at the output of git log), and then do this:

git reset --hard <sha1-commit-id>
like image 188
koninos Avatar answered Oct 08 '22 16:10

koninos