Git - 只克隆版本库的一部分,并只获取该部分的内容? [英] Git - clone only part of the repository and get pulls only for that part?

查看:786
本文介绍了Git - 只克隆版本库的一部分,并只获取该部分的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  repo1 / 
/ module1
/ module2
/ module3


repo2 /
/ module4
/ module5

因此,在我的测试服务器上,我加载这些存储库就好像它是可以的,因为我得到了所有的代码。但是在客户端服务器上,假设我只需要他的项目模块,它们可以说是 repo2 ,而且还需要一个来自以前项目的模块 repo1



有没有办法从 repo1 克隆 module1 ,然后如果我更新 repo1 中在 module1 中更改的任何内容,我会为 repo1 (它只有部分repo克隆)执行 pull ,它会更新它吗? p>

更新
所以在客户端服务器上会有两个这样的回购:

  repo1 / 
/ module1

repo2 /
/ module4
/ module5


解决方案

您可以使为每个回购稀疏结帐

  mkdir repo1 
cd myrepo1
git init
git config core.sparseCheckout true
git remote add -f origin / url / of / repo1
echo module1 / *> .git / info / sparse-checkout
git fetch
git checkout master

(与repo2相同)


So let say I have two repositories with specific modules (or subdirectories) like this:

repo1/
  /module1
  /module2
  /module3


repo2/
  /module4
  /module5

So on my test server I load these repositories like it is and it is OK, because I get all the code. But on client server, let say I only need his project modules which let say is repo2, but also one module from previous project which is repo1.

Is there a way I could clone from repo1 only module1 and then if I would update anything in repo1 that is changed in module1, when I would do pull for repo1 (which would have only part of repo cloned), it would update it?

Update So on client server there would be two repos like this:

repo1/
  /module1

repo2/
  /module4
  /module5

解决方案

You can make a sparse checkout for each repos:

mkdir repo1
cd myrepo1
git init
git config core.sparseCheckout true
git remote add -f origin /url/of/repo1
echo module1/*> .git/info/sparse-checkout
git fetch
git checkout master

(same for repo2)

这篇关于Git - 只克隆版本库的一部分,并只获取该部分的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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