Git子树:只使用subrepository而不是整个存储库 [英] Git subtree: Use only subrepository instead of whole repository

查看:118
本文介绍了Git子树:只使用subrepository而不是整个存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用一些第三方库的项目。
因此,目录结构如下所示:

  MY_COOL_PROJECT 
3rdParty
LIB_1
LIB_2

MY_PROJECT

库位于不同的存储库中。因此,如果我想为第三方库使用git存储库,我可以这样做:

  git subtree add --prefix 3rdParty / LIB_1 --squash http://My3rdPartyLibs.com/lib1.git master 

但是,在lib1 .git版本库中只有一个我需要的bin文件夹。它还包含诸如文档,示例等文件夹。我怎样才能将我的存储库与lib1 / bin文件夹而不是整个存储库连接?这甚至有可能吗?

解决方案

通常情况下,git repo会被完全克隆/加载。
$ b

您可以 稀疏结帐 (Git1.7 +),但前提是您不打算做任何修改并将其推回。请参阅此示例



$ $ $ $ g $ init
在/tmp/si-sandbox/.git/ $ b中初始化了空的Git仓库$ b(master)$ git config core.sparsecheckout true
(master)$ echo message-store />> .git / info / sparse-checkout
(master)$ git remote add origin git://github.com/iwein/Spring-Integration-Sandbox.git
(master)$ git pull origin master






OP user2070238 $ b


这有一些变化。

因为,我使用的子模块必须使用




  echo MY_FOLDER / *>> .git / info / modules / MY_MODULE / sparse-checkout 




某些原因 MY_FOLDER / 部分在没有 *


$时不起作用b $ b

I have a project that uses some 3rd Party libraries. So the directory structure is something like:

MY_COOL_PROJECT
   3rdParty
      LIB_1
      LIB_2
   Source
      MY_PROJECT   

The libraries are located in separate repositories. So, if I want to use a git repository for the 3rd Party libraries I can do:

git subtree add --prefix 3rdParty/LIB_1 --squash http://My3rdPartyLibs.com/lib1.git master

However, inside lib1.git repository there is only one bin folder I need. It contains also folders such as documentation, examples, etc. How can I only "connect" my repository with lib1/bin folder instead of the whole repository? Is that even possible?

Normally, a git repo is done to be fully cloned/loaded.

You could go for a sparse checkout (Git1.7+), but only if you don't intent to do any modification and push those back. See this example:

$ git init
Initialized empty Git repository in /tmp/si-sandbox/.git/
(master) $ git config core.sparsecheckout true
(master) $ echo message-store/ >> .git/info/sparse-checkout
(master) $ git remote add origin git://github.com/iwein/Spring-Integration-Sandbox.git
(master) $ git pull origin master


The OP user2070238 reports:

This worked with a few changes.
Because, I use submodule I had to use

 echo MY_FOLDER/* >> .git/info/modules/MY_MODULE/sparse-checkout 

And for some reason the MY_FOLDER/ part was not working without *

这篇关于Git子树:只使用subrepository而不是整个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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