I had a project called twitter-clone on Github. And accidentally i added this repository as the remote origin of the project I am currently working on and made a force push to master branch. And my twitter clone is gone. Is there any way that i can revert it?
CodePudding user response:
the simplest way is to use GitHub API for something that is a little like having access to reflog.
First, find the commit id before you pushed your changes by using the Events API.
curl -u <username> https://api.github.com/repos/:owner/:repo/events
This will return a JSON blob of the most recent events in the repo — pretty much like the reflog command. You would have to sift through the blob to locate your commit(s) that was lost. You can these use the ref/sha to create a new branch.
Create a new branch for the ref using the Create Reference API:
curl -u <github-username> -X POST -d ‘{“ref”:”refs/heads/<new-branch-name>”, “sha”:”<sha-from-step-1>"}’ https://api.github.com/repos/:owner/:repo/git/refs
Took from this post: https://medium.com/git-tips/githubs-reflog-a9ff21ff765f
If there is not garbage collection that was run on this project in the time since you force pushed your changes it will work.