简体   繁体   中英

How to restore deleted files on GitHub

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM