在Git中使用多个源代码库 [英] Utilizing multiple source repositories in Git

查看:178
本文介绍了在Git中使用多个源代码库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将使用Codeigniter作为框架的新项目,Flexiauth用于用户登录,然后是我自己的自定义代码。 codeigniter和flexiauth都使用Git,我希望能够从这些中拉出来让我的代码保持最新。



我是否将它们分别添加为单独的远程存储库,只是做拉?不会造成冲突吗?



是否有更好的方法将多个git存储库作为大型项目的组件处理? h2_lin>解决方案

是的,有。 Git支持子模块



我推荐 Pro Git在线书籍的相关部分作为一个很好的开始指出了这一点,但基本的想法是你使用下面的语法添加一个子模块:

pre $ g $ submodule add git:/ /github.com/chneukirchen/rack.git rack

其中 rack 是要设置为子模块的文件夹。在克隆repo时,需要在克隆后运行以下命令来获取子模块:

  git submodule init 
git子模块更新

通过这种方式,您可以将第三方库完全退出回购库,它作为子模块。



或者,这是作曲家是为了解决。 Laravel 4框架实际上是以其所有组件都与Composer一起安装的方式构建的,您可以运行 composer update 来全部更新它们。你可以想象将Code Composer和CodeIgniter一起使用(Phil Sturgeon在 http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter ),但是Flexiauth不会出现在 https://packagist.org/ ,所以我会使用Git子模块。


I've got a new project that will be using Codeigniter as the framework, Flexiauth for the user login stuff, and then my own custom code for my application. Both codeigniter and flexiauth use Git and I'd like to be able to do pulls from those to keep my code up to date.

Do I add each as a seperate remote repository and just do pulls? Wont that create conflicts?

Is there a better method for handling multiple git repositories as components of a larger project?

解决方案

Yes, there is. Git supports submodules.

I recommend the relevant section of the Pro Git book online as a good starting point for figuring this out, but the basic idea is you add a submodule using the following syntax:

git submodule add git://github.com/chneukirchen/rack.git rack

where rack is the folder you want to set up as a submodule. When cloning the repo, you need to run the following commands after the clone to fetch the submodules:

git submodule init
git submodule update

That way, you keep the third party library out of your repo entirely and only record it as a submodule.

Alternatively, this is the problem Composer is meant to solve. The Laravel 4 framework is actually built in such a way that all of its components are installed with Composer, and you can just run composer update to update them all. You could conceivably use Composer with CodeIgniter (Phil Sturgeon wrote a blog post on doing so at http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter), however Flexiauth doesn't appear in the repository at https://packagist.org/, so I would go with using Git submodules.

这篇关于在Git中使用多个源代码库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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