Git:如何将第 3 方库克隆到我的应用程序存储库的子目录中?

发布于 2024-10-17 00:32:15 字数 426 浏览 1 评论 0原文

我正在尝试找出将第 3 方库(来自 Janrain 的engage.iphone)克隆到我自己的应用程序目录结构中的正确方法,这样我就可以提取最新的更改并将它们与我在本地所做的任何更改合并。我还希望在推送时将第 3 方库(与我的更改合并)包含在我自己的应用程序的 git 存储库中。

结构会是这样的:

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
    ...

我怎样才能安全地设置它?设置完成后,是否有任何特殊的合并流程?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦忆晨望 2024-10-24 00:32:15

子模块是实现此目的的最简单方法。

使用子模块有两种常见方法 - 添加新子模块和初始化现有子模块。

添加新子模块

从本地存储库的根目录运行:

git submodule add;外部/engage.iphone

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

但是,您可能不会自己添加子模块...

初始化现有子模块

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

git submodule init

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

git submodule update

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

git submodulesync

运行此命令将所有子模块更新到其远程 HEAD,除非您在添加子模块时指定了特定提交!指定特定的子模块将仅同步该子模块。

在真正的 git 时尚中,init 命令可以与 update 结合使用以节省时间:

git submodule update --init

当然,一旦您了解了 .gitmodules 和 .git/config 使用的布局(类似于配置中的分支和远程部分),您始终可以手动更新它们。

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

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文