Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)
edited by

I want to discard all changes done after commit <commit-hash>. So I did:

git reset --hard <commit-hash>

Now I want to do the same with my remote. How can I do this? I have done some commits (and pushes) after <commit-hash> and I just want to discard them all. It is just something that went terribly wrong in the way and I don't want to make it worse than it is already. 

I basically want to rewind my origin/master to <commit-hash>

1 Answer

+1 vote
by (50.2k points)

Use the following commands:

git reset --hard <commit-hash>

 git push -f origin master

Here assuming origin as your remote and master as your branch.

However, you should avoid doing this if anyone else is working with your remote repository and has pulled your changes. In that case, it would be better to revert the commits that you don't want, then push as normal.

Since from your question it's clear that you have already used git reset --hard to reset your master branch, you may need to start by using git reset --hard ORIG_HEAD to move your branch back to where it was before.

I hope this will help to reset the remote to a certain commit.

by (27.5k points)
Thank you! This one worked for me.

Browse Categories

...