简体   繁体   English

如何有选择地克隆 git 存储库

[英]How to selectively clone a git repository

I am new to Git.我是 Git 的新手。 I want to clone a large remote repository lets say xyzcodebase .我想克隆一个大型远程存储库,比如xyzcodebase The structure of repo is like I have src folders for different functional areas as shown below. repo 的结构就像我有不同功能区域的 src 文件夹,如下所示。

xyzcodebase
|
|__ Func area 1
|
|__ Func area 2

I work on Functional area 2 hence while cloning I don't want code from Functional area 1 (large size) which will save lots of my time.我在Functional area 2上工作,因此在克隆时我不想要Functional area 1 (大尺寸)的代码,这将节省我的大量时间。 So that after cloning I will have only Functional area 2 source code on my local repository.这样克隆后,我的本地存储库中将只有Functional area 2源代码。

Is there a way to accomplish such selective cloning of git repository?有没有办法完成git存储库的这种选择性克隆?

Thanks in advance for your help在此先感谢您的帮助

No, there is no way to only clone one directory.不,没有办法只克隆一个目录。 Git stores history as changes to whole repository instead of storing only subtrees as SVN. Git 将历史记录存储为对整个存储库的更改,而不是仅将子树存储为 SVN。

If your project contains multiple functionalities, then maybe it would be better to split it into some sub-projects, with different repositories, and then include other repositories as submodules in master project.如果您的项目包含多个功能,那么最好将其拆分为一些具有不同存储库的子项目,然后将其他存储库作为子模块包含在主项目中。 But it depends how your project is organized.但这取决于您的项目是如何组织的。

This is a hacky solution that might in special cases help with your issue.这是一个 hacky 解决方案,在特殊情况下可能会帮助您解决问题。 Specifically if you are only interested in a single file you could simply download it from the console (in Unix) via wget : wget https://raw.githubusercontent.com/GITHUBUSER/REPOSITORY/master/file.ending特别是如果您只对单个文件感兴趣,您可以通过wget从控制台(在 Unix 中)简单地下载它: wget https://raw.githubusercontent.com/GITHUBUSER/REPOSITORY/master/file.ending

You can get the link of a specific file by navigating to it in github and then click on "raw".您可以通过在 github 中导航到特定文件的链接,然后单击“raw”来获取特定文件的链接。

There is some support for this appearing recently, but the Git server needs to support partial clone so the objects from the other directory can be excluded from the generated pack file.最近出现了一些对此的支持,但 Git 服务器需要支持部分克隆,以便可以从生成的包文件中排除其他目录中的对象。

See also https://docs.gitlab.com/ee/topics/git/partial_clone.html#filter-by-file-path and git-sparse-checkout .另请参阅https://docs.gitlab.com/ee/topics/git/partial_clone.html#filter-by-file-pathgit-sparse-checkout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM