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.

trz
  • 161
  • 1
  • 1
  • 5
  • cant you reset the non protected branch to the commit you desire ? – john Smith Mar 12 '16 at 13:47
  • 2
    Possible duplicate of [Git: how to reverse-merge a commit?](http://stackoverflow.com/questions/1809484/git-how-to-reverse-merge-a-commit) – wimh Mar 12 '16 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 '16 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 '16 at 10:14
  • @msw Is not an option. The admins don't want/can change it. – trz Mar 13 '16 at 10:18

1 Answers1

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

Soumyadip Das
  • 1,781
  • 3
  • 16
  • 34
CodeWizard
  • 128,036
  • 21
  • 144
  • 167