如何在git项目中嵌套git项目? [英] how to nest a git project in a git project?

查看:387
本文介绍了如何在git项目中嵌套git项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:将git repo嵌套在git repo WITHOUT 中,将第二个repo存储在主机主repo中.仓库必须是两个单独的实体.这样,我可以轻松地更新客户端站点的基本代码(用于多个站点).

Issue: Nest a git repo in a git repo WITHOUT storing the second repo in the hosts master repo. The repos need to be two separate entity's. This way I can easily update a client sites base code (used on multiple sites).

两个存储库的原因:我有一个基本的php框架,供我的项目使用.每个客户端都有自己的存储库,该存储库具有该站点所需的文件.由于git/submodules的工作方式,我必须保留"framework"作为主存储库,而将"clients code"作为子模块.原因是我必须具有 index.php&根目录中的.htaccess (框架的一部分).很好,因为我的框架旨在根据需要进行扩展.我可以将所需的所有客户端文件放在站点"文件夹中,并将其存储为单独的存储库.明显的缺点是,要设置站点,您必须先安装框架存储库",然后再安装客户端存储库".由于这些是私有的,因此此设置很好.我还喜欢能够从另一个项目更新我的框架的好处.现在麻烦的是,我从该克隆进行的任何推送都包括客户端代码".另外,由于我需要对框架进行本地测试时需要使用相同的设置,因此子模块将添加回主框架存储库中.我很好想,为什么不只是克隆保存客户端代码"的站点"文件夹,然后将该文件夹添加到忽略列表中.我必须手动更新每个文件,但那还是可以的.但是torisegit似乎认为它现在是一个子项目(有限的支持),我什至不能将该文件夹添加到忽略列表中.因此,我假设嵌套git克隆是不好的,但我做错了.

Reason for two repos: I have a base php framework that my projects use. Each client gets their own repo that has the files required for that site. Due to the way git/submodules work I have to keep the "framework" as the master repo with the "clients code" as the submodule. The reason is I MUST have the index.php & .htaccess (part of the framework) in the root. That's fine since my framework is designed to extend as needed. I can just put any client files I need in the "site" folder and store that as a separate repo. The obvious downside is in order to setup the site you have to first install the "framework repo" then install the "client repo". Since these are private this setup is fine. I also liked the benefit of being able to update my framework from another project. Trouble is now any push's I do from that clone include the "client code". Also since I need the same setup for my local test of the framework that submodule gets added back to the main framework repo. I thought well why not just clone the "site" folder that holds the "client code" and add that folder to the ignore list. I have to update each by hand but again thats fine. However torisegit seems to think that its now a subproject (limited support) and I cant even add that folder to the ignore list. So i'm assuming nesting git clones is bad but I could be doing it wrong.

目标:我需要能够部署两个存储库.我的框架"肯定是基础/根仓库.然后,我需要以某种方式在基本存储库内的文件夹中嵌入第二个客户端"存储库.客户端"存储区从不存储框架代码,仅存储其自己的代码.我希望能够在不存储有关客户端代码"的任何内容的情况下更新并推送对框架代码"(其alpha版本的大量错误修复)的更改,因此我可以轻松地将其克隆到新站点的新文件夹中.客户端代码再次存储在框架根目录上一级的单个文件夹中.(请参见下面的示例).当我尝试复制粘贴文件夹,甚至手动将其添加到忽略文件时,将其作为git克隆会破坏TortoiseGit并可能破坏git.将其添加为子模块会将其添加到主存储库中,因此在我克隆它时会尝试添加它.

Goal: I need to be able to deploy two repos. My "framework" im sure has to be the base/root repo. Then I need to embed somehow a second "client" repo in a folder inside the base repo. The "client" repo never stores the framework code, just its own code. I want to be able to update and push changes to the "framework code" (its alpha so lots of bug fixes) without it storing anything about the "client code" so I can easly just clone it into a new folder for a new site. Again client code is stored in a single folder one level up from the frameworks root. (See example below). Doing this as a git clone breaks TortoiseGit and possibly git when I try to copy paste a folder and even add it by hand to the ignore file. Adding it as a submodules adds it to the master repo so when I clone it trys to add it.

最终想法:也许子项目可以工作,但是似乎对其没有太多支持,我不知道如何使用它.我试图将其保留在主要工具中,以便我的两个主要工具TortoiseGit和NetBeans支持所有内容.也许有一种方法可以不将子模块存储在主仓库中,但是我找不到它.也许子文件夹可以工作,但似乎又没有太多支持.似乎最简单的情况是它只是忽略文件夹,但至少当我尝试使用TortoiseGit时似乎坏了,但可能做错了.

Final Thoughts: Perhaps subprojects would work but there does not seem to be much support for it and I dont understand how to use it. Im trying to keep it to major tools so that my two main tools TortoiseGit and NetBeans support everything. Perhaps there is a way to not store a submodule in the master repo but I cant find it. Maybe subfolders would work but again there does not seem to be much support for it. Seems like the simplest would be it just ignore the folder but at least TortoiseGit seems to break when I try this but I could be doing it wrong.

示例文件夹布局:


-.git  (framework repo)
- system    *framework folder
-- foo   *framework folder
-- bar   *framework folder
- site  (root for second repo aka client)
-- .git  (client repo)
-- config.php   *client file
- index.php    *framework file
- .htaccess    *framework file

系统"文件夹index.php和.htaccess是PHP框架的一部分,并且对我所有的站点都是通用的.站点"文件夹包含包含该站点文件的第二个存储库.第二种选择是重写我的框架,以便将其存储在自己的文件夹中并由新的index.php调用.但是,这是一次重大的重写,对其编写方式造成了噩梦.加上处理.htaccess文件的问题,因为该文件必须位于根目录中.当然,我可以复制它,但是对该文件所做的任何更改都不会立即被更新.但是在这一点上,我认为这是唯一的方法.

The "system" folder, index.php and .htaccess are part of the PHP framework and are generic to all my sites. The "site" folder holds the second repo that contains the files for that site. The second option is to rewrite my framework so that its stored in its own folder and gets called by a new index.php. However this is a major rewrite with a pathing nightmare do to the way its written. Plus the issue of dealing with the .htaccess file since that has to be in the root. Sure I could copy it but then any changes to that file would not get updated in a pull. But at this point i think its the only way.

希望这是有道理的.我没有想法,但真的想让它起作用.

Hope this makes sense. I'm out of ideas but really want to get this to work.

推荐答案

您始终可以仅将第二个存储库克隆到所需的第一个存储库中,然后将第二个存储库添加到您的 .gitignore 文件中

You can always just clone the second repository where ever inside the first you like, then add the second's folder to your .gitignore file.

在上面的示例中,您只需添加:

In your example above, you'd just add:

site/

到您的 .gitignore .

这篇关于如何在git项目中嵌套git项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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