Git:如何将第三方库复制到我应用程序库的子目录中? [英] Git: How to clone a 3rd party library into a subdirectory of my app's repository?

查看:198
本文介绍了Git:如何将第三方库复制到我应用程序库的子目录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出将第三方库(来自Janrain的engage.iphone)克隆到我自己的应用程序目录结构中的正确方法,这种方式可以让我获得最新的更改并将它们与任何更改合并我在本地制作。我还希望第三方库(与我的更改合并)在我推送时包含在自己的应用程序的git仓库中。



结构就像这样:

  myApp /<  - 这是我的应用,它是它自己的git仓库
external /
engage.iphone /< - 这是我想跟上的第三方库最新的
mySource1.h
mySource2.m
...
code>

如何安全地设置它?有没有什么特别的过程可以在设置之后进行合并?

解决方案

子模块是最简单的方法完成这一步。



有两种常用的子模块工作方式 - 添加新模块和初始化现有子模块。



添加新子模块



从本地存储库的根目录运行: git submodule add< repository> external / engage.iphone



add 命令适用于最初将一个子模块添加到存储库中,而不是使用现有子模块克隆存储库时)。它添加了另一个可以位于本地或远程路径上的存储库(请记住,如果您发布存储库,其他开发人员需要访问此存储库!)到存储库根目录中的.gitmodules文件,然后将存储库克隆到您指定的位置;在上面的例子中 external / engage.iphone 。在此阶段,您的系统上有子存储库文件,它在.gitmodules文件和本地存储库的配置文件中都被列为子模块。

可能不会自己添加子模块...



初始化现有子模块



如果您克隆已添加子模块的存储库,则情况会有所变化。在这种情况下,.gitmodules文件将包含其中列出的子模块以检索它们的位置,但是您的本地存储库配置对它们一无所知,并且实际文件在您的系统中尚不存在。首先,您需要初始化子模块:

git子模块init



这将通过您的.gitmodules中列出的任何存储库运行,并将它们添加到您的.git / config。 Git现在知道存储库,但它尚未克隆它,因此运行:

git子模块更新



您可以随时运行此命令来更新已注册的子模块,即克隆缺失的模块。



git submodule sync< submodule>



运行此命令将所有子模块更新到远程HEAD,除非您指定了特定的提交你做了子模块添加!指定一个特定的子模块只会同步该模块。



在真正的git中, init 命令可以与 update 以节省时间:

git submodule update --init 在配置中)。



所有的细节都可以在手册页找到( kernel.org版本)。


I'm trying to figure out the proper way to clone a 3rd party library (engage.iphone from Janrain) into my own app's directory structure in a way that will let me pull the latest changes and merge them with any changes that I make locally. I also want the 3rd party library (merged with my changes) to be included in the git repo for my own app when I push it.

Structure would be something like this:

myApp/  <- this is my app, which is its own git repo
    external/
        engage.iphone/ <- this is the 3rd party library I want to keep up-to-date
    mySource1.h
    mySource2.m
    ...

How can I set it up this way safely? Is there any special process for merging later on down the road, after it's been set up?

解决方案

Submodules are the easiest way to accomplish this.

There are two common ways of working with submodules - adding new ones and initialising existing ones.

Adding New Submodules

From the root of your local repository run:

git submodule add <repository> external/engage.iphone.

The add command is for when you're initially adding a submodule to the repository, as opposed to when you've cloned a repository with existing submodules). It adds another repository which can be on a local or remote path (remember that other developers need access to this if you publish your repository!) to the .gitmodules file in your repository root, then clones the repository into the location you specified; external/engage.iphone in the above example. At this stage you have the sub-repository files on your system and it is listed as a submodule in both the .gitmodules file, your local repositories' config.

However you might not be adding the submodules yourself...

Initialising Existing Submodules

Things change a bit if you're cloning a repository that already has submodules added to it. In this situation the .gitmodules file will have the submodules listed in it with locations to retrieve them from, but your local repository config knows nothing about them and the actual files don't yet exist on your system. First you need to initialise the submodules:

git submodule init

This will run through any repositories listed in your .gitmodules and add them to your .git/config. Git now knows about the repository but it hasn't actually cloned it yet, so run:

git submodule update

You can run this command anytime to update the registered submodules, i.e. clone missing ones.

git submodule sync <submodule>

Run this to update all submodules to their remote HEAD, unless you specified a specific commit when you did the submodule add! Specifying a specific submodule will only sync that one.

In true git fashion the init command can be combined with the update to save time:

git submodule update --init.

Of course, you can always manually update your .gitmodules and .git/config once you've learnt the layout they use (similar to branch and remote sections in the config).

All the specifics can be found in the man page (kernel.org version).

这篇关于Git:如何将第三方库复制到我应用程序库的子目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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