Git:从远程获取特定对象 [英] Git: fetch a specific object from a remote

查看:52
本文介绍了Git:从远程获取特定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在工作中,我们必须应对非常庞大的git存储库(90Go).尝试调整本地副本上的某些内容(我在打包文件时遇到错误,尝试将其解压缩)之后,可能已删除了一些目标文件.例如:

At work we have to cope with a very huge git repository (90Go). After having tried to tweak some things on my local copy (I had errors with a pack file, tried to unpack it), I might have deleted some object files. For instance:

>git gc

> git gc

错误:无法读取af9ed8 [:snip:]

error: Could not read af9ed8[:snip:]

致命:坏树对象af9ed8 [:snip:]

fatal: bad tree object af9ed8[:snip:]

错误:无法运行重新打包

error: failed to run repack

如何从远程存储库中获取特定对象(在这种情况下,该对象带有哈希值af9ed8 ...)?

How can I fetch a specific object (in that case the one with the hash af9ed8...) from a remote repository?

推荐答案

如果您具有对远程或包含该对象的任何其他完整存储库的文件系统访问权限,则应该能够在其中运行:

If you have filesystem access to the remote or any other intact repository containing this object, you should be able to go there and run:

git cat-file tree af9ed8 > 9ed8...

请注意,这仅需要对存储库的只读访问权限(您可以在其他位置写入文件),因此它应该非常安全,甚至可以以对文件系统没有写权限的用户身份进行操作.然后,您可以将其传输/复制到回购中的适当位置:

Note that this only requires read-only access to the repo (you can write the file elsewhere) so it should be very safe, and you could even do it as a user who doesn't have write permissions to the filesystem. You can then transfer/copy it into the appropriate place in your repo:

cp path/to/9ed8... .git/objects/af/9ed8...

松散的对象存储在目录中,其哈希值的前两位数字;文件名是哈希的其余部分.

Loose objects are stored in directories with the first two digits of the hash; the filenames are the rest of the hash.

如果该对象在远程端松动,您也可以直接将其复制到 .git/objects 之外,但是如果已打包,则必须使用 git unpack-objects ,我想该仓库中的packfile太大了.最好的方法是将打包文件复制到损坏的存储库中,删除所有损坏的对象,然后使用 git unpack-objects<packfile ,它不会解压缩已经存在的任何对象.

If the object is loose on the remote end you could also just directly copy it out of .git/objects, but if it's packed, you'd have to unpack it with git unpack-objects, and I imagine the packfiles in that repo are prohibitively large. The nicest way to do that would be to copy the packfile into your corrupted repo, delete any corrupted objects, and then use git unpack-objects < packfile, which will not unpack any objects which already exist.

我不确定如何通过普通的远程命令执行此操作;即使是较低级别的 git fetch-pack 仍然在引用级别上运行,通过必要的提交来获取包以完成引用.我怀疑您可能可以偷偷摸摸地做一些事情,例如删除所有引用该树的提交对象( git fsck 可能会帮助您找到它们).我真的希望您能够创建一个指向该对象的标签,将其推送到远程,然后尝试从远程获取标签(将其哄骗到获取对象),但是看起来Git非常小心,不要让您制作或操作指向不存在的对象的标签.

I'm not sure how to do it via normal remote commands; even the lower-level git fetch-pack still operates at a ref level, fetching a pack with the necessary commits to complete the ref. I suspect that you might be able to do something sneaky like deleting all of the commit objects which reference that tree (git fsck might help you find them). I was really hoping you might be able to create a tag pointing to that object, push it to the remote, then try to fetch the tag from the remote (coaxing it into fetching the object) but it looks like Git is quite careful not to let you make or manipulate a tag pointing to a nonexistent object.

这篇关于Git:从远程获取特定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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