niceseb niceseb - 1 year ago 179
Git Question

How to revert to previous commit and remove later commits in Git

Wanted to revert to previous commit by

$ git reset --hard commit_sha

Which seems to revert successfully with HEAD is now at that previous commit but within PyCharm log I still see the later commit in branch history.

So my question is how to remove that later commit ? i.e. image here, I want to remove commit

Do I right click on
or the commit named TEMP CHANGE GROUP and select 'Reset Current Branch to Here'?

Because the
is still in BitBucket?

$ git reset --hard 7e260f7

enter image description here

enter image description here

Answer Source

Your branch master on remote origin is still pointing to the commit you're trying to remove. You need to force update the remote branch using git push origin master --force.

There is also a difference between reset and revert which is worth knowing.

When you use git reset you move the branch pointer to the commit you specify. You essentially move backwards through the history. Docs:

When you use git revert you reverse the changes that the commit you specify made and create another commit containing those reversed changes. In this instance you will create an additional commit with the reversed change set. Docs:

I hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download