'Revert branch pushed on origin with incorrect HEAD

I have accidently pushed a branch with git push origin HEAD:DEVELOP and it merged all the commits to develop branch. The branch contained lots of unwanted commits. How to revert this and set develop branch to original state



Solution 1:[1]

If you know the correct git commit id, to which it should be reverted. You can use the git command

git push --force <remote> <commit-id>:<branch name>

I have used this previously and it works. NOTE: please proceed with caution and make sure commit id you pass is correct.

Reference: https://stackoverflow.com/a/40580976/4556029

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 manpreet