[英]Is there any way to restore a GitHub repo that has been deleted with the code and commit history saved locally?
Essentially I was on a team that had a GitHub repository that is now deleted.本质上,我所在的团队拥有一个现已删除的 GitHub 存储库。 I still have the code saved locally on my computer and would like to put the project on my personal GitHub.我仍然将代码保存在本地计算机上,并希望将项目放在我个人的 GitHub 上。 I would like there to be some way to have the commit history still intact so that the other team members can have credit for the work they did.我希望有某种方法可以使提交历史保持完整,以便其他团队成员可以对他们所做的工作感到满意。 However, since the repo is gone I can no longer fork it to do this.但是,由于 repo 已经消失,我不能再分叉它来执行此操作。 Is there any way to do this or should I just recreate the repo and credit them in the README?有什么办法可以做到这一点,还是我应该重新创建回购并将它们记入自述文件中? Or just leave it off entirely?还是完全不做?
First of, the commit history is stored in the .git folder of each copy of the repo.首先,提交历史存储在每个 repo 副本的.git文件夹中。 It is not stored or managed by Github, rather Github's copy of the repo also has a .git folder that contains the same commit history as your local copy.它不是由 Github 存储或管理的,而是 Github 的 repo 副本也有一个.git文件夹,其中包含与本地副本相同的提交历史记录。 Basically, as long as that .git folder is " intact ", then the commit history is still going to be " intact " when you push the repo somewhere, anywhere else.基本上,只要.git文件夹是“完整的”,那么当您将 repo推送到其他任何地方时,提交历史仍然是“完整的”。
Second, Github does support recovering or restoring a deleted repo, see Restoring a deleted repository from the Github docs.其次,Github确实支持恢复或恢复已删除的存储库,请参阅从 Github 文档中恢复已删除的存储库。 But that option depends on if you owned the account or organization that created the old repo, and if the old repo wasn't deleted for more than 90 days, and if that old repo has no forks.但该选项取决于您是否拥有创建旧存储库的帐户或组织,以及旧存储库是否已超过 90 天未被删除,以及该旧存储库是否没有分叉。 If you can restore it, then you can fork it to your personal account.如果您可以恢复它,那么您可以将其分叉到您的个人帐户。
If restoring the old repo is not an option, the other (simpler, IMHO) option is to create a new repo and push your local copy to that new remote.如果恢复旧的仓库不是一个选项,另一个(更简单,恕我直言)选项是创建一个新的仓库并将您的本地副本推送到该新远程。 When you say you " have the code saved locally on my computer ", I am assuming it is still a working git repo like this:当您说您“将代码保存在我的计算机上本地”时,我假设它仍然是一个有效的 git 存储库,如下所示:
$ cd myproject
$ git log
$ git remote -v
origin git@github.com:ginomempin/my-old-repo.git (fetch)
origin git@github.com:ginomempin/my-old-repo.git (push)
where my-old-repo.git is the deleted Github repo and the logs still show all the commits.其中my-old-repo.git是已删除的 Github 存储库,日志仍显示所有提交。 Go to Github and create an entirely new repo. Go 到 Github 并创建一个全新的存储库。 When it redirects you to the "your new repository is empty" page, notice the instructions on pushing an existing repo:当它将您重定向到“您的新存储库为空”页面时,请注意推送现有存储库的说明:
Because you already have an origin
in your local copy, you can instead change it to the new URL:因为您已经在本地副本中有一个origin
,您可以将其更改为新的 URL:
$ git remote set-url origin git@github.com:ginomempin/my-new-repo.git
$ git remote -v
origin git@github.com:ginomempin/my-new-repo.git (fetch)
origin git@github.com:ginomempin/my-new-repo.git (push)
Now simply push it all to the new repo:现在只需将其全部推送到新的仓库:
$ git push --all
That new repo will now contain all the old commits, as if it was just like the old one.新的 repo 现在将包含所有旧的提交,就好像它就像旧的一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.