如何恢复远程崩溃的Git回购? [英] How do I restore a remote crashed Git repo?

查看:172
本文介绍了如何恢复远程崩溃的Git回购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好。我们都知道,回购的每个克隆都可以作为克隆回购的备份。精细。另外,每个使用 git fetch 更新历史记录的远程服务器都将备份到应用了 git fetch 的应用程序中。 / p>

但是,当涉及到恢复的备份时:我该怎么做?什么是正确的相反命令 git fetch



我的一个Git仓库存在问题:

  git status 
致命:无法读取树0d2f806b01ded93e76a6f2c7a68429939f483026

是的,我可以以某种方式开始修复回购,但是– 幸运我 –在我的笔记本回购之前,我在远程计算机上执行了 git fetch notebook



因此,我在桌面上有一个回购,其中包含我死亡回购的所有最新参考(如 refs / remote / notebook / fix / issue1 refs / remote / notebook / master 等)。

如何使用此信息在笔记本上恢复回购?

我发现一个简单的方法:在code> desktop 上找到

笔记本分支:

  git branch -r | grep笔记本> notebookbranches 

现在我们有一个名为 notebookbranches 它包含笔记本的所有分支。


$ b 笔记本上,创建一个新的空的存储库,称为 myrepo2

  git init myrepo2 
pre>

桌面上添加此回购:

  git remote add myrepo2 // notebook / D $ / myrepo2#在Windows上使用共享名
git fetch myrepo2#获取myrepo2的当前状态

现在,在文件 notebookbranches 上打开您最喜欢的编辑器。该文件目前看起来像这样:

  notebook / fix / issue1 
notebook / master
...

修改文件如下所示:

  git push myrepo2 -f refs / remotes / notebook / fix / issue1 
git push myrepo2 -f refs / remotes / notebook / master
...

将此文件设置为可执行文件并执行它。



脚本完成后,所有分支都存在于 myrepo2 回购库中,但存储在 .git / refs / remotes / notebook

将所有存在的文件移动到 .git / refs / heads / 文件夹。



然后,你就完成了。


Okay. We all know that every clone of a repo is good as a backup of the cloned repo. Fine. Also, every remote whose history gets updated with git fetch is backed up in that repo where git fetch was applied.

But when it comes to restore of the backup: how do I do it? What is the right opposite command of git fetch?

One of my Git repo has issues:

git status
fatal: unable to read tree 0d2f806b01ded93e76a6f2c7a68429939f483026

Yes, I could start repairing the repo somehow, but – lucky me – I did a git fetch notebook on a remote machine right before my repo on notebook died.

So, I have a repo on desktop, where I have all the latest refs of my died repo (as refs/remote/notebook/fix/issue1, refs/remote/notebook/master, etc.).

How do I restore the repo on notebook with this information?

解决方案

I found an easy way:

on desktop, ask git for the known remote branches of notebook:

git branch -r | grep notebook > notebookbranches

Now we have a file called notebookbranches that holds all the branches of the notebook.

On notebook, create a fresh empty repo called myrepo2

git init myrepo2

Add this repo as remote on desktop:

git remote add myrepo2 //notebook/D$/myrepo2 # working on Windows, use share name
git fetch myrepo2 # fetch current state of myrepo2

Now, open your favourite editor on the file notebookbranches. The file currently looks like this:

notebook/fix/issue1
notebook/master
...

Modify the file to look like this:

git push myrepo2 -f refs/remotes/notebook/fix/issue1
git push myrepo2 -f refs/remotes/notebook/master
...

Make this file executable and execute it.

When the script has finished, all the branches are present on the myrepo2 repo but are stored under .git/refs/remotes/notebook.

Take all the files present here and move them to the .git/refs/heads/ folder.

Then, you're done.

这篇关于如何恢复远程崩溃的Git回购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆