我在 Github 上有一個名為 twitter-clone 的專案。我不小心添加了這個存盤庫作為我目前正在處理的專案的遠程源,并強制推送到 master 分支。我的推特克隆不見了。有什么辦法可以恢復它嗎?
uj5u.com熱心網友回復:
最簡單的方法是使用 GitHub API 來做一些類似于訪問 reflog 的事情。
首先,在使用事件 API 推送更改之前找到提交 ID。
curl -u <username> https://api.github.com/repos/:owner/:repo/events
這將回傳存盤庫中最新事件的 JSON blob — 與 reflog 命令非常相似。您將不得不篩選 blob 以找到丟失的提交。您可以使用 ref/sha 創建一個新分支。
使用 Create Reference API 為 ref 創建一個新分支:
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
取自這篇文章:https : //medium.com/git-tips/githubs-reflog-a9ff21ff765f
如果在您強制推送更改后沒有在此專案上運行垃圾收集,它將起作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/380583.html
