If you wish to rewind the master branch of the repository to a previous pushed commit, simply run this command — of course, with the appropriate commit hash:
git reset --hard a0b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9
git push --force
This may have unintended consequences if, for instance, there are collaborators on your repository. But, I am sure you know what you're doing 😉
Answer from GirkovArpa on Stack OverflowIf you wish to rewind the master branch of the repository to a previous pushed commit, simply run this command — of course, with the appropriate commit hash:
git reset --hard a0b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9
git push --force
This may have unintended consequences if, for instance, there are collaborators on your repository. But, I am sure you know what you're doing 😉
I think you're looking for the --force argument.
You can reset to a specific commit with git reset --hard {commit sha} and then force the change to origin with git push --force.
Note that if others are using your repo, they will need to use git pull --force or they may inadvertently put your unwanted commit back into the repo.
I recommend reading the help documentation for git reset and git push before taking action.
revert to previous commit on github?
How do I undo the last commit without losing changes?
Undoing last commit
Made a Mistake commit to master and it isn't going away!
Videos
Hi, I would like to revert to a previous commit. I believe I did this correctly on my local repository using git reset --hard commit-hash. I would like to push this to github but of this results in
error: failed to push some refs to 'https://github.com/shmish/smartmark.git' hint: Updates were rejected because the tip of your current branch is behind
I am the only working on this repository, so I am not worried about conflicts, I am trying to move back one commit.