Git:如何仅克隆Git存储库的子目录? [英] Git: How do I clone a subdirectory only of a Git repository?

查看:347
本文介绍了Git:如何仅克隆Git存储库的子目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的Git存储库,该存储库的根目录有两个子目录:

/finisht
/static

当它位于 SVN 中时,/finisht在一个地方被检出,而/static已在其他地方签出,就像这样:

svn co svn+ssh://admin@domain.com/home/admin/repos/finisht/static static

有没有办法用Git做到这一点?

解决方案

EDIT :从Git 2.19开始,这终于有可能,如在answer .

考虑批准该答案.

注意:在Git 2.19中,仅实现了客户端支持,仍然缺少服务器端支持,因此仅在克隆本地存储库时才起作用.另请注意,大型Git托管人,例如GitHub实际上并不使用Git服务器,而是使用自己的实现,因此即使在Git服务器中显示了支持,也并不意味着它可以自动在Git主机上使用. (OTOH,由于他们不使用Git服务器,因此可以在自己的实现中更快地实现它,然后再将其显示在Git服务器中.)


不,在Git中是不可能的.

在Git中实现这样的工作将是一项巨大的工作,这将意味着不再能够保证客户端存储库的完整性.如果您有兴趣,请在git邮件列表中搜索有关稀疏克隆"和稀疏访存"的讨论.

通常,在Git社区中的共识是,如果您有几个始终独立检出的目录,则它们实际上是两个不同的项目,应该位于两个不同的存储库中.您可以使用 Git子模块将它们重新粘合在一起. /p>

I have my Git repository which, at the root, has two sub directories:

/finisht
/static

When this was in SVN, /finisht was checked out in one place, while /static was checked out elsewhere, like so:

svn co svn+ssh://admin@domain.com/home/admin/repos/finisht/static static

Is there a way to do this with Git?

解决方案

EDIT: As of Git 2.19, this is finally possible, as can be seen in this answer.

Consider upvoting that answer.

Note: in Git 2.19, only client-side support is implemented, server-side support is still missing, so it only works when cloning local repositories. Also note that large Git hosters, e.g. GitHub, don't actually use the Git server, they use their own implementation, so even if support shows up in the Git server, it does not automatically mean that it works on Git hosters. (OTOH, since they don't use the Git server, they could implement it faster in their own implementations before it shows up in Git server.)


No, that's not possible in Git.

Implementing something like this in Git would be a substantial effort and it would mean that the integrity of the clientside repository could no longer be guaranteed. If you are interested, search for discussions on "sparse clone" and "sparse fetch" on the git mailinglist.

In general, the consensus in the Git community is that if you have several directories that are always checked out independently, then these are really two different projects and should live in two different repositories. You can glue them back together using Git Submodules.

这篇关于Git:如何仅克隆Git存储库的子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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