Git:如何将子模块推送到远程存储库? [英] Git: how to push submodule to a remote repository?

查看:179
本文介绍了Git:如何将子模块推送到远程存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git来跟踪我正在处理的网站。我在我的机器上工作,并按照本指南推送提交到远程服务器:使用Git管理网站。上周我尝试使用Git子模块来管理一些第三方库,今天我试着推送到服务器,发现在服务器中所有的子模块目录是空的。



我尝试添加并提交对本地子模块的更改,确实 git status 工作目录是干净的。



我能做什么?

解决方案

子模块的关键在于它们是仓库内的git仓库,父仓库只知道应该在子模块中检出哪些提交 - 它对内容一无所知。所以一个服务器只知道没有填充子模块的父项目,自然不会看到它们。



您需要在某个时候初始化您的服务器上的子模块。它看起来像你的工作树有一个独立于你的repo的设置,所以就像 git checkout -f 一样,你需要适应: GIT_WORK_TREE = / path / to /任何git子模块更新--init 。之后,当你的hook在推后运行 git checkout -f 时,它还需要运行 git submodule update (再次与工作树适当设置)。

但它比这更复杂。您没有提供任何有关您的子模块来自哪里的信息,但子模块知道它的来源,就像您的存储库一样。初始化时,它会尝试从该原点进行克隆,并且更新它通常需要从该原点进行提取。如果像我怀疑的那样,第三方库的来源是公开的,你没有访问权限,那么你将不得不为子模块设置自己的中央存储库。当你在其中一个子模块中提交时,你会推到它的中央仓库,然后然后推送父项目,这样当它试图更新其他地方的子模块时,它可以获取它们。 p>

因此,回顾一下,工作流程如下所示:


  • -party子模块(或其独立克隆)

  • 将第三方库推送到其中央存储库

  • 在父库中添加子模块)提交

  • 将父项目推送到其中央仓库中

  • 父项的中央仓库钩子检出到您的服务器,并在那里更新子模块


I use git to track website I'm working on. I work on my machine and push commits to a remote server configured following this guide: using Git to manage a website.

Last week I tried using Git submodules to manage some third party libraries and today I tried pushing to the server, finding out that in the server all the submodule directories are empty.

I tried adding and commiting changes to the local submodule, indeed git status says that the working directory is clean.

What can I do?

解决方案

The point of submodules is that they are git repositories within repositories, and the parent repo only knows what commit should be checked out in the submodule - it knows nothing about the content. So a server only aware of the parent project, which hasn't populated the submodules, will naturally see nothing in them.

You'll need to at some point initialize the submodules on your server. It looks like you've got a setup with your work tree separate from your repo, so just like with that git checkout -f, you'll need to accommodate that: GIT_WORK_TREE=/path/to/whatever git submodule update --init. Afterwards, when your hook runs git checkout -f after pushing, it'll also need to run git submodule update (again with the work tree appropriately set).

But it's more complicated than this. You haven't given any information about where your submodules came from, but a submodule is aware of its origin, just like your repository is. When you initialize one, it tries to clone from that origin, and updating it often requires fetching from that origin. If as I suspect, the origin for your third-party libraries is something public that you don't have push access to, you're going to have to set up your own central repositories for the submodules. When you commit in one of the submodules, you'd push to its central repo, and then push the parent project, so that when it tries to update submodules elsewhere, it's able to fetch them.

So, to recap, the workflow is something like this:

  • commit in third-party submodule (or standalone clone of it)
  • push third-party library to its central repository
  • add submodule in parent repo (make it aware of the new commit) and commit
  • push parent project to its central repo
  • parent's central repo hook checks out to your server, and updates submodule there

这篇关于Git:如何将子模块推送到远程存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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