Friday, September 21, 2012

Ooops - hide it under the carpet!

I've done it. You've done it, too. In fact, many have done it and many will do it, for sure.

Pushed something unwanted to a public git repository by accident.

Well, if you are lucky, you notice it very early. In 10 seconds, usually :)
Damage is done, let's try to undo it - fast.

Solution #1

1) Remove the incriminated commit from the local repo:
git rebase -i

2) Forced push to the remote repo:
git push -f origin +branchname

Solution #2

(works for undoing the last N commit only)
git push -f origin HEAD^:branchname

What's left? Crossing fingers and hope noone has pulled the repo during your manoeuvres :)