1

I have many branches on my repo. I accidentally pushed to branch named feature/customer. Now I want to roll back that push. How can I rollback that push on branch feature/customer in git?

mnestorov
  • 4,116
  • 2
  • 14
  • 24
ahsan
  • 277
  • 1
  • 5
  • 18

2 Answers2

1

Assuming that the feature/customer branch is shared by other people, and that someone else may have already pulled your accidental commit, the best thing to do would be to revert the commit:

# from feature/customer
git revert HEAD

This will add a new commit on top of the customer branch which will functionally undo whatever your accidental commit may have introduced. Now you only need to do a regular push again to get this revert commit to the repository.

Note that if the accidental commit contains any sensitive information, you could try to overwrite the remote branch. However, there would always still be the possibility that someone else already pulled. In addition, the previous accidental commit would still be present in the remote reflog for some time.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

If you have permissions on the remote. You can do the following:

git push -f origin last_known_good_commit:branch_name

Also, you can refer to Undoing a 'git push'

nitishagar
  • 9,038
  • 3
  • 28
  • 40