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

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

问题描述

我有我的 Git 存储库,它在根目录下有两个子目录:

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

/finisht
/static

当这是在 SVN 中时,/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

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

Is there a way to do this with Git?

推荐答案

EDIT:从 Git 2.19 开始,这终于成为可能,正如在此 答案.

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

考虑对该答案投赞成票.

Consider upvoting that answer.

注意:在Git 2.19中,只实现了客户端支持,仍然缺少服务器端支持,所以它只在克隆本地存储库时有效.还要注意大型 Git 托管商,例如GitHub,实际上并没有使用 Git 服务器,他们使用自己的实现,因此即使 Git 服务器中显示支持,也并不自动意味着它可以在 Git 主机上运行.(OTOH,因为他们不使用 Git 服务器,所以他们可以在自己的实现中更快地实现它,然后它才会出现在 Git 服务器中.)

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.)

不,这在 Git 中是不可能的.

No, that's not possible in Git.

在 Git 中实现这样的东西将是一项巨大的努力,这意味着无法再保证客户端存储库的完整性.如果你有兴趣,可以在 git 邮件列表上搜索关于sparse clone"和sparse fetch"的讨论.

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.

总的来说,Git 社区的共识是,如果您有多个始终独立检出的目录,那么它们实际上是两个不同的项目,应该存在于两个不同的存储库中.您可以使用 Git Submodules 将它们重新粘合在一起.

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 存储库的子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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