1

I was searching for a way to remove my last GitHub commit and found this command on:

How can I remove a commit on GitHub?

It worked. The problem is that I accidentally did it to the wrong repository.

I read in comments that commit is not really deleted, but

"...this only moves the branch pointer."

How can I recover from this command and revert to the last commit?

Community
  • 1
  • 1
Boykodev
  • 850
  • 1
  • 10
  • 23

1 Answers1

1

GitHub has an hidden reflog: the GitHub Events API.

See "Does github remember commit IDs?"

By curling the https://api.github.com/repos/<user>/<repo>/events, and looking for push events, you can find the commit pushed to master before your own, and push again that commit, provided you had a local clone of that repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Is there any chance to recover the commit if I don't have a local clone of that repo? – Boykodev Dec 23 '15 at 08:57
  • @Boykodev is there anyone else who has clone that repo? He or she can simply push back his/her current HEAD in a `git push --force`. – VonC Dec 23 '15 at 09:03