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

时间:2016-03-23 10:18:52

标签: git github git-submodules github-pages git-subtree

我正在制作一个使用git对文件进行版本控制的webapp,它可以选择在GitHub页面上托管一些缺少的功能(git-only后端不支持这些功能)。

现在“app”本身与用户内容分离,用户内容受版本控制但应用程序不是(或者至少不需要用于应用程序本身的功能),但两者都需要上传到github页面并隔离内容的版本控制,并对应用程序与内容拥有不同的权限,我将应用程序本身托管在gh-pages中,内容作为git 子模块在gh内部-pages repo。

这很有效,app / site已构建并在username.github.io/sitename/上公开,所有内容都可访问,除非有捕获。

由于某些原因子模块内容repo在特定提交时被引用而不仅仅是最新版本的repo,这意味着我不能只更新内容仓库和让一切工作但还必须在每个内容回购提交上更新app repo以引用子模块的最新版本。

由于我几乎从来没有真正更新应用程序仓库,除非有新版本的应用程序,但我每天更新内容仓库,以及内容仓库应该可由许多人编辑的事实,这有点单调乏味人们,但很少有应用程序回购。

所以我的问题是:

  • 如何定义子模块以始终引用repo的最新提交?
  • 如何仅通过更新子模块仓库触发网站构建?
  • gh-pages repo如何始终反映其子模块的最新版本,以便gh-pages网站始终提供最新内容?

我如何创建子模块

# 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.

2 个答案:

答案 0 :(得分:2)

请在线查找我的回复:

  

如何定义子模块以始终引用repo的最新提交?

这不可能从git-submodule的概念和目的出发。虽然为了便于更新,您可以为子模块配置分支。

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

  

如何仅通过更新子模块仓库触发网站构建?

您可以使用子模块上的git-hooks编写命令来触发对子模块存储库上的提交进行构建。子模块上配置的git-hook的工作方式与主要repo工作的git-hook相同。子模块挂钩的驻留位置为.git/modules/your-sub-module-name/hooks参考:https://git-scm.com/docs/githooks

  

gh-pages repo如何始终反映其子模块的最新版本,以便gh-pages网站始终提供最新内容?

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

May this answer可以帮助你在子模块库的git-hooks内对主repo进行一些git操作。

答案 1 :(得分:-1)

  

问题在于,由于某种原因,子模块内容存储库在特定提交时被引用而不仅仅是最新版本的存储库,这意味着我不能只更新内容存储库并使一切工作但也必须在每次内容回购提交时更新app repo以引用最新版本的子模块。

您必须添加以下命令

# 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   在每个签出的子模块中计算任意shell命令。

来自子模块文档:

  

当克隆或拉动包含子模块的存储库时,默认情况下不会检出这些;

     

initupdate子命令将维护子模块,并在工作树中以适当的版本进行检查。

     

<强> update

     

通过克隆缺失的子模块并更新子模块的工作树来更新已注册的子模块以匹配超级项目所期望的

相关问题