可以使 github 存储库始终引用其子模块存储库的最新版本吗?

Can a github repo be made to always refer to the latest version of its submodule repos?

我正在制作一个使用 git 对文件进行版本控制的网络应用程序,它可以选择托管在 Git 中心页面上,但缺少一些功能(git-仅后端)。

现在 "app" 本身与用户内容分离,用户内容受版本控制但应用程序不受版本控制(或者至少不需要为应用程序本身的功能),但两者都需要上传到 github 页面并隔离内容的版本控制,并且对应用程序与内容具有不同的权限,我将应用程序本身托管在 gh-pages 中,内容作为 git submodule 在 gh-pages 仓库中。

这有效,app/site 已构建并在 username.github.io/sitename/ 上公开,所有内容均可访问,但有一个问题。

要注意的是,由于某种原因 子模块内容回购在特定提交时被引用 而不仅仅是最新版本的回购,这意味着我不能只更新内容回购并使一切正常,但还必须更新应用回购以引用子模块的最新版本,在每个内容回购提交

这有点乏味,因为除非有新版本的应用程序,否则我实际上几乎不需要更新应用程序存储库,但我每天更新内容存储库,而且内容存储库应该是可编辑的很多人,但应用程序回购很少。

所以我的问题是:


我如何创建子模块

# Create app master + app-content master, then:
git init
git remote add origin https://github.com/01AutoMonkey/app.git
git submodule add https://github.com/01AutoMonkey/app-content ./wiki
cd wiki
git remote add origin https://github.com/01AutoMonkey/app-content.git
# And then push to both repos and create a gh-pages branch.
# The site is now running but if I update app-content the update isn't reflected on the site until I refer to the new commit in the app repo.

The catch is that for some reason the submodule content repo is referred to at a specific commit instead of just the latest version of the repo, which means I can't just update the content repo and have everything work but also have to update the app repo to refer to the latest version of the submodule, on every content repo commit.

您必须添加以下命令

# Create app master + app-content master, then:
git init
git remote add origin https://github.com/01AutoMonkey/app.git
git submodule add https://github.com/01AutoMonkey/app-content ./wiki

#
#
#
git submodule init

# Run this command every time you want to update the submodule
git submodule update
#
#
#
cd content
git remote add origin https://github.com/01AutoMonkey/app-content.git

现在获取每个子模块的最新代码:

# loop on every submodule and checkout the latest code
git submodule foreach git pull origin master

foreach Evaluates an arbitrary shell command in each checked out submodule.


来自子模块文档:

When cloning or pulling a repository containing submodules however, these will not be checked out by default;

the init and update subcommands will maintain submodules checked out and at appropriate revision in your working tree.

update

Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules

请查找我的内联回复:

How can I define a submodule to always refer to the latest commit of a repo?

从git-子模块的概念和目的来看,这是不可能的。尽管为了便于更新,您可以为子模块配置一个分支。

$ git config -f .gitmodules submodule.hs-srvcommon.branch sprint 是将用 sprint 覆盖默认主分支的命令。 (hs-srvcommon为子模块目录名)

How can I trigger a build of the site by only updating the submodule repo?

您可以使用子模块上的 git-hooks 编写命令来触发在子模块回购上所做的提交的构建。在子模块上配置的 git-hooks 的工作方式与主 repo 工作的 git-hooks 的工作方式相同。子模块的钩子所在位置为.git/modules/your-sub-module-name/hooks 参考:https://git-scm.com/docs/githooks

How can the gh-pages repo always reflect the latest version of its submodules, so that the gh-pages site is always serving the latest content?

哦,使用子模块的 git-hooks 应该也是可行的。您需要做的就是在子模块上配置 post-commit/push-hooks,以便它们也更新对子模块提交 sha id 的主要 repo 引用。

可能 this answer 可以帮助您从子模块仓库的 git-hooks 中对主仓库执行一些 git 操作。