0

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

ashwin
  • 186
  • 1
  • 6
  • 2
    Note that `git push` never does a *merge*. It only does a "fast forward". (Git does call some merges "fast-forward merge", which can lead one to think that a fast-forward is a merge, but it isn't, really.) This doesn't answer your question, it's just a wording issue. – torek May 11 '22 at 12:34

1 Answers1

4

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

manpreet
  • 636
  • 5
  • 20
  • You *may* be able to retrieve the correct hash ID using `git reflog origin/develop`. This depends on how recently you ran `git fetch`. If this doesn't help, you generally just have to scan through commit hash IDs as shown by `git log`, very carefully. – torek May 11 '22 at 12:35