预加载git存储库? [英] Pre-load git repository?

查看:58
本文介绍了预加载git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我已经在本地拥有相同的文件,是否可以从文件中预加载"本地的文件,而不是从远程存储库中提取较大的文件目录?我已经在本地拥有与远程服务器相同的文件,只是它们不在本地存储库中.

If I already have the same files locally, instead of pulling down a large directory of files from a remote repository is there a way to "pre-load" my local repository with the files? I already have the same files locally that are on the remote, they just are not in the local repo.

这是我的情况:

我有一个远程网站,其中包含大量(很多演出)资源(图像,PDF,swfs,flvs)目录.我已经为该远程站点建立了一个git存储库,并使用.gitignore文件从存储库中排除了大资源目录,从而在本地克隆了它.

I've got a remote web site that has a large (many gigs) directory of resources (images, PDFs, swfs, flvs). I've set up a git repository for this remote site and I have cloned it locally, using the .gitignore file to exclude the big resource directory from being included in the repo.

我现在想将大型资源目录作为远程存储库的一部分,但这将大大增加存储库的大小,当我执行下一个本地请求时,我将等待很长时间.因此,我基本上希望有一种方法可以告诉git我要问你拉回突然变大的仓库,但我已经掌握了使它如此庞大的大部分内容"?还是这可能会反过来呢?我先将文件添加到本地存储库中,然后以某种方式使存储库知道它们具有相同的文件,而无需传输?

I'd like to make the big resources directory part of the remote repo now, but that's going to drastically increase the size of the repo and when I do my next local pull I'm in for a really long wait/download. So I'm basically hoping there is a way of telling git "I'm going to ask you to pull that repo that is all of a sudden much bigger but I've already got most of what's making it so big"? Or would this maybe go the other way, where I add the files to my local repo first and then somehow the repositories work it out that they've got the same files and no transfer is necessary?

当将新开发人员带入一个大型项目时,这也将派上用场,并且大部分项目都可以通过DVD提供,而不必克隆/下载庞大的存储库.

This would also come in handy when new developers are brought onto a large project and the bulk of it could be provided on DVDs instead of them having to clone/download a huge repo.

推荐答案

我建议您要非常谨慎,养成习惯,不要在git中添加千兆字节的二进制文件,而不必考虑

I suggest you be very careful about making a habit out of adding gigabytes of binaries into your git without looking into options like git-annex.

现在.仅本地拥有文件本身不足以让Git使用它们.您可以使用 git hash-object 手动将大型二进制文件添加到大型网络划分的任一侧的Git的对象数据库中,并在另一侧创建一个包含完全相同的文件的提交,但是当推送/获取此类提交时,Git不够聪明,无法找出这一点这些对象已经在另一侧;因为需要传输的提交不存在,因此大的 斑点将包含在通过导线传输的结果packfile中.为了避免这种情况,您必须手动复制所有提交和树对象,但忽略大的Blob.可行,但可能会带来更多麻烦.

Now. Just having the files themselves locally isn't enough for Git to use them. You could use git hash-object to manually add the big binaries to Git's object database on either side of the great network divide and create a commit containing the exact same files on the other side, but when pushing/fetching such a commit Git isn't smart enough to figure out that those objects already exist on the other side; because the commit that needs to be transmitted doesn't exist the big blobs will be included in the resulting packfile that's transmitted over the wire. To avoid this you'd have to manually copy all commit and tree objects but omit the big blobs. Doable but probably more trouble than it's worth.

一种更现实的方法是对网络传输进行一次打击,并对未来的传输保持警惕.您可以拥有一个可供人们克隆的本地镜像.如果那还不够快,则表明您的git太大.

A more realistic approach is to take the hit of the network transfer once and be smart about future transfers. You can have a local mirror that people can clone from. If that's also not fast enough it's an indication that your git is too big.

您还可以使用git clone --reference <ref> <url>克隆git,其中<​​c2>是包含要克隆的git的本地目录.这将重用参考git中的所有对象,从而使克隆速度非常快.但是,如 git clone联机帮助页,新克隆将直接引用旧克隆中的对象,因此,如果删除了旧克隆,您将遇到麻烦.要实际复制对象,可以在克隆后运行git repack -a.

You can also clone the git with git clone --reference <ref> <url>, where <ref> is a local directory containing the git you're cloning. This will reuse all objects from the reference git, making the clone extremely fast. However, as noted in the git clone manpage, the new clone will directly refer to the objects in the old clone so if the old clone is deleted you're in trouble. To actually copy the objects you can run git repack -a after cloning.

git clone --reference /some/old/clone http://example.com/some/git dirname
cd dirname
git repack -a
rm .git/objects/info/alternates

最后一条命令删除了到参考git的链接,因此Git以后不会尝试在其中查找对象.

The last command deletes the link to the reference git so Git won't try to look for objects there in the future.

例如在上分发Git存储库DVD或类似的存储机制着眼于 git bundle .参见例如如何git捆绑一个完整的仓库.

To distribute a Git repository on e.g. DVD or similar storage mechanisms look into git bundle. See e.g. How to git bundle a complete repo.

这篇关于预加载git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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