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.
You’ll have to revert those commits.
Technically what it does is that it removes those changes and makes a new commit, undoing them.
Now, reverting them will leave them on the history stil, but usually that is ok. If that’s totally unacceptable only then look at the solutions like filter-branch and force pushes.