Git - clone only part of the repository and get pu

2019-02-19 03:14发布

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

标签: git git-clone
2条回答
女痞
2楼-- · 2019-02-19 03:40

For the record I will add my dilemma where I wanted all files in the root folder of the repository and two of the subdirs, but not the other two (very large) dirs. This is what I came up with after also looking here

git init SOME_REPO
cd SOME_REPO/
git remote add origin ssh://<git server>:<port>/SOME_REPO
git config core.sparsecheckout true
echo '/*' >> .git/info/sparse-checkout
echo '!first_not_wanted_dir/*' >> .git/info/sparse-checkout
echo '!second_not_wanted_dir/*' >> .git/info/sparse-checkout
git pull --depth=1 origin master
查看更多
做自己的国王
3楼-- · 2019-02-19 03:44

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)

查看更多
登录 后发表回答