14

Is there a way to undo commits on a protected branch?

I mean, If you pushed an wrong commit, on a non protected branch you can undo it reseting the HEAD to the last desired commit or reverting the wrong commits and forcing the push then. But protected branches does not allow force pushing. What's the way to fix it on this case?

Edit: The specified (rigtht) commit is not a merge.

5
  • cant you reset the non protected branch to the commit you desire ?
    – john Smith
    Mar 12, 2016 at 13:47
  • 2
    Possible duplicate of Git: how to reverse-merge a commit?
    – wimh
    Mar 12, 2016 at 13:48
  • Talk with the person who has admin rights on the protected branch. They are the one who accepted your pull request and will best know how they want it fixed.
    – msw
    Mar 12, 2016 at 15:21
  • @johnSmith Is a protected branch. I did another branch (a "restarotaion point") from the last right commit reseting the HEAD to the last right commit and creating a new branch. But I want to fix the protected branch if possible.
    – trz
    Mar 13, 2016 at 10:14
  • @msw Is not an option. The admins don't want/can change it.
    – trz
    Mar 13, 2016 at 10:18

1 Answer 1

19

reverting the wrong commit

git revert SHA-1    
git commit ....
git push origin <branch>

If your branch is protected, and you can't perform a git push -f ... then you can simply execute a revert.

git revert
Revert some existing commits

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.