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

问题描述



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

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

使用jQuery作为子模块创建一个仓库并将我自己的外部仓库添加为远程仓库的过程是什么。



这是设置,如果我推/拉到我自己的远程,外部将保持完好?

解决方案

  1. 您有一个项目 - 将它称为 MyWebApp ,它已经有一个github仓库

  2. 您想在 jquery仓库中使用您的项目

  3. 您想将jquery回购作为子模块加入您的项目中。

子模块真的很容易引用和使用。假设您已经将MyWebApp设置为repo,请从终端发出以下命令:

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

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

  git子模块update --init --recursive 

您现在应该将所有最新的代码克隆到子模块中。如果jquery repo发生变化,并且想要取消最新的代码,只需再次发出子模块更新命令。请注意:我的项目中通常有许多外部存储库,因此我总是将回购站放在外部目录下。



在线有一些关于子模块(和一般的git)的好信息,它们以易于阅读的形式呈现时尚。或者, git help submodule 也会提供很好的信息。或者查看git wiki上的。



我注意到了这个博客文章,它讨论了子模块并将它们与Subversion的svn:externals机制进行了比较:




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

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

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

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

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

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

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.

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.

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

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

10-18 23:01