Git 中依赖的子模块、子树或其他东西?

本文介绍了Git 中依赖的子模块、子树或其他东西?的处理方法,对大家解决问题具有一定的参考价值

问题描述

我有一个大型项目的情况,该项目有很多模块/库及其各自的存储库.这些模块中的大多数是其他模块的依赖项,而不是项目的依赖项.现在已经到了主项目有几个子项目和许多模块共享的地步.一些依赖关系的深度超过 3-4 级.

I have a situation with a larger project that has lots of modules/libraries with their respective repos. Most of these modules are dependencies of other modules which are than dependencies of a project. And now it has come to the point where the main project has several sub-projects and many of modules are being shared. Some dependencies are more than 3-4 levels deep.

我已经读到可以在项目中更新/拉取子模块,但这仅适用于第一级子模块.假设这些子模块有自己的子模块(第 2 级),并且一些第 1 级子模块共享相同的第 2 级子模块.此外,第二个 lvl 子模块有它们的子模块(lvl3)等.现在我应该做的是首先推送第三级所做的更改,而不是更新第二级模块中的子模块并推送这些,现在我可以进入第一级,更新和推送,最后更新我的项目子模块并推送它们.

I have read that it is possible to update/pull submodules inside of a project, but that works only for 1st level of submodules. Let's say that those submodules have their own submodules (2nd level) and that some 1st level submodules share the same 2nd level submodules. Also, 2nd lvl submodules have their submodules (lvl3), etc. Now what I should do is to firstly push changes made in 3rd level, than update submodules in 2nd level modules and push those, now I can go to 1st level, update and push, and finally update my project submodules and push those.

这现在不仅是更多的工作,但它仍然不能解决我的问题,为什么我需要这样的东西,那就是能够在对依赖于每个存储库的更改进行更改时轻松推送和拉取多个存储库其他.很容易发生团队中的某个人在 5 个 repo 中的 4 个中推送更改,而当其他成员拉除此之外的所有内容时,生产线会停止,直到发现错误.

This is now not only more work, but it still doesn't solve my problem why I need something like this and that is to be able to easily push and pull multiple repositories when changes were being made to those that dependent on each other. It can easily happen that someone in a team pushes changes in 4 of 5 repos, and when other members pull all except this one production line stops until error has been found.

对此我能做些什么?也许一些关于工作流程的建议,有没有其他人遇到过这个问题,或者 Git 中是否有一些功能可以解决这个问题.

What can I do about this? Maybe some advices about workflow, has anyone else encountered this problem or is there some feature in Git that solves this.

推荐答案

我会推荐android使用的repo工具.它足够通用,可以与任何 git 托管环境一起使用,并且不需要像子模块那样需要超级项目提交来更新子项目.

I would recommend the repo tool that android uses. It is generic enough to work with any git hosting environment, and doesn't require super-project commits to update sub-projects like submodules does.

首先,按照此处所述安装客户端:https://source.android.com/source/downloading.html#installing-repo

First, install the client as described here: https://source.android.com/source/downloading.html#installing-repo

然后创建一个清单存储库.清单是一个 xml 文件,它描述了 git 存储库位置和它们应该被签出的路径.像这样:

Then create a manifest repository. A manifest is an xml file that describes git repository locations and paths they should be checked out to. Like this:

mkdir manifests
cd manifests
git init

创建清单文件default.xml:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote name="github" fetch="ssh://git@github.com" />
  <default remote="github" revision="master" />
  <project name="git/git.git" path="git" />
  <project name="libgit2/libgit2.git" path="vendor/libgit2" />
</manifest>

然后添加、提交清单,然后推送到某处:

Then add, commit the manifest, and push somewhere:

git add default.xml
git commit -m "My first try at a manifest file"
git push git@github.com:myusername/manifests.git master

现在您可以使用 repo 命令了.

Now you are ready to use the repo command.

mkdir myproject
cd myproject
repo init -u git@github.com:myusername/manifests.git
repo sync -j2

您的 git 存储库将被克隆.您现在可以像往常一样在每一个中工作.在您推送到任何项目后,其他人需要做的只是 repo sync,它们将被更新到最新版本(另请参阅 repo start).

Your git repositories will be cloned. You can now work in each one like normal. After you push to any of the projects, all anyone else needs to do is a repo sync and they will be updated to the latest revision (also see repo start).

您可能需要重新组织您的项目.通常,您可能将其他模块作为子目录 (myproject/vendor/dependency).虽然您仍然可以使用 repo 维护此布局,但它会导致 git 存储库与另一个 repo 签出.使用 .gitignore 技巧可能可行,但我建议重新组织您的项目,这样存储库就不需要相互签出.

You may have to reorganize your project. Typically you might have other modules as sub-directories (myproject/vendor/dependency). While you can still maintain this layout using repo, it will cause a git repository to be checked out with another repo. With .gitignore trickery it might be workable, but I would recommend reorganizing your project so repositories do not need to be checked out within each other.

请参阅 https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt 获取 xml 文件中每个项目的完整说明.

See https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt for a complete explanation of each item in the xml file.

参见 https://source.android.com/source/using-repo.html 用于简单的命令参考.repo help 也很有用.注意:除非您使用 Gerrit,否则您应该忽略 repo upload.

See https://source.android.com/source/using-repo.html for a simple command reference. repo help is also very useful. Note: you should ignore repo upload unless you are using Gerrit.

这就像在 git 中添加远程一样.这意味着我们可以使用给定名称引用 url.

This is just like adding a remote in git. It means we can refer to the url with a given name.

默认元素指定项目的默认选项.这相当于在每个项目上添加 remoterevision 项.这只是节省了一些输入.

The default element specifies default options for the projects. This is equivalent of adding the remote and revision items on every project. This just saves some typing.

这是真正的工作发生的地方.repo sync 将获取名称并使用斜杠将其附加到远程.在这种情况下,远程是默认的 github,因此它将获取 url ssh://git@github.com/git/git.git.它会将项目签出到指定版本的路径 git(在这种情况下,默认为 master).随后的 repo sync 将检出最新版本(在分支的情况下).

This is where the real work is happening. repo sync will take the name and append it to the remote using a slash. In this case the remote is the default github, so it will get the url ssh://git@github.com/git/git.git. It will checkout the project to the path git at the specified revision (in this case the default is master). Subsequent repo syncs will checkout the latest revision (in the case of a branch).

这篇关于Git 中依赖的子模块、子树或其他东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1173

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1071

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this-&gt;id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:808

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this-&gt;id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:900

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:931

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:878

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:865

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:834

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1734

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1309