如何设置 git 项目以使用外部 repo 子模块? [英] How to set up a git project to use an external repo submodule?

查看:34
本文介绍了如何设置 git 项目以使用外部 repo 子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个接收远程存储库的存储库.

I'd like to create a repo which pulls in a remote repo.

例如,假设 jQuery 作为一个子模块:

For example, let's say jQuery as a submodule:

git://github.com/jquery/jquery.git

使用 jQuery 作为子模块创建 repo 并将我自己的外部添加为远程 repo 的过程是什么.

What would be the process of creating a repo with jQuery as a submodule and adding my own external as a remote repo.

此外,一旦设置完毕,如果我推/拉到我自己的遥控器,外部是否会保持完整?

Also once this is setup, if I push / pull to my own remote, will the external remain intact?

推荐答案

  1. 您有一个项目 -- 称之为 MyWebApp,它已经有一个 github 存储库
  2. 您想在您的项目中使用 jquery 存储库
  3. 您想将 jquery 存储库作为子模块拉入您的项目.
  1. You have a project -- call it MyWebApp that already has a github repo
  2. You want to use the jquery repository in your project
  3. You want to pull the jquery repo into your project as a submodule.

子模块真的非常容易参考和使用.假设您已经将 MyWebApp 设置为存储库,从终端发出以下命令:

Submodules are really, really easy to reference and use. Assuming you already have MyWebApp set up as a repo, from terminal issue these commands:

cd MyWebApp
git submodule add git://github.com/jquery/jquery.git externals/jquery

这将创建一个名为 externals/jquery* 的目录并将其链接到 github jquery 存储库.现在我们只需要初始化子模块并将代码克隆到它:

This will create a directory named externals/jquery* and link it to the github jquery repository. Now we just need to init the submodule and clone the code to it:

git submodule update --init --recursive

您现在应该将所有最新代码克隆到子模块中.如果 jquery 存储库发生更改并且您想要拉取最新代码,只需再次发出 submodule update 命令.请注意:我的项目中通常有许多外部存储库,因此我总是将这些存储库分组在externals"目录下.

You should now have all the latest code cloned into the submodule. If the jquery repo changes and you want to pull the latest code down, just issue the submodule update command again. Please note: I typically have a number of external repositories in my projects, so I always group the repos under an "externals" directory.

在线 Pro Git Book 有一些关于子模块(和 git in一般)以易于阅读的方式呈现.或者,git help submodule 也会提供很好的信息.或者查看 git wiki 上的 Git 子模块教程.

The online Pro Git Book has some good information on submodules (and git in general) presented in an easy-to-read fashion. Alternately, git help submodule will also give good information. Or take a look at the Git Submodule Tutorial on the git wiki.

我注意到这个博客条目谈论子模块并将它们与 Subversion 的 svn:externals 机制进行比较:http://speirs.org/blog/2009/5/11/understanding-git-submodules.html

I noticed this blog entry which talks about submodules and compares them to Subversion's svn:externals mechanism: http://speirs.org/blog/2009/5/11/understanding-git-submodules.html

* 作为最佳实践,您应该始终将子模块放在它们自己的目录中,例如 Externals.如果不这样做,您的根项目目录会很快变得非常混乱.

这篇关于如何设置 git 项目以使用外部 repo 子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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