Git: Reset to older commit / Undo changes & Push

This article shows how you can reset your git state to any older/previous commit and then push to your origin repository.

Reset to older commit


git reset --hard <commit-hash>

Example:


git reset --hard 39fdf70

Force push to origin repository


git push origin --force

# OR
git push --force

If you only want to reset in your origin repository and not in your local repository, then:


git push origin +<commit-hash>:<branch-name>

Example:


git push origin +39fdf70:master 

where,
39fdf70 is the commit that you want your origin repo to reset to
+ is used for force push

More discussion on this here.

Hope this helps. Thanks.