本文介绍了单个文件作为Git子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



到目前为止,我显然遇到了类似于他们的子模块 - 差不多 - 符合法案。我的项目是一个简单结构的PHP MVC框架:


  • / app

  • core.php

  • / core



其中应用是包含特定于应用程序的控制器,模型,视图等的文件夹,而 core 包含一般用途的文件夹,例如一个登录控制器。 core.php 文件本身是所有请求的全局处理程序。



因此,共享代码我的MVC框架的部署是 core.php core



我可以看到如何将 core 转换为Git子模块,但不是 core.php



这甚至可能吗?我是否需要重新构建我的框架,以便 core.php 位于核心文件夹内,以便我可以整个文件夹是一个子模块,还是有更好的方法?

解决方案

也许你最好保持core.php和核心在一个单独回购,然后将其用作远程。
然后,您可以通过将其拉入任何使用的项目来进行管理。为了做到这一点,只需将新项目作为单独的git仓库启动,然后将核心仓库作为子仓库。

本章将向您展示如何做到这一点:



更新参考:
原始参考:



这比你在本书前一部分建议的设置(6.6)要好一些。



看看它;这可能会有所帮助。


I'm trying to ascertain best-practices for shared code amongst Git repositories.

So far, I've obviously come across submodules which seem like they - almost - fit the bill. My project is a PHP MVC framework with a simple structure:

  • /app
  • core.php
  • /core

Where app is a folder containing application-specific controllers, models, views etc. while core contains those of general use, e.g. a login controller. The core.php file itself is the global handler for all requests.

As such, the shared code amongst all of my deployments of this MVC framework is core.php and core.

I can see how it is possible to turn core into a Git submodule, but not core.php.

Is this even possible? Do I need to re-architecture my framework so that core.php resides inside the core folder so I can make the whole folder a submodule, or is there a better way?

解决方案

Perhaps you are best off maintaining core.php and core in a separate repo, and then using it as a remote.Then you can manage it by pulling it into any project it is used. In order to do this, just start the new project as a separate git repo, and then pull in the 'core' repo as a subtree.

This chapter shows you how to do it:

Updated Reference: http://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_subtree_mergeOriginal Reference: https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging

It is a little better for you than the setup advised in the previous section of the book (6.6).

Look at it; it might be helpful.

这篇关于单个文件作为Git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:32