[英]Git: Push a local git submodule, including submodule files, to a remote bare repository
I have two local projects which I manage with git
, one being dependent on the other – like this: 我有两个使用git
管理的本地项目,一个依赖于另一个,例如:
project A/
├── project B/
│ ├── file B₁
│ ├── file B₂
│ ├── …
It makes sense to me to have project B
as a git submodule of project A
. 将project B
作为project A
的git子模块对我来说很有意义。
Now, I have set up a remote bare repository for project A
for backup and sharing purposes. 现在,我为project A
建立了一个远程裸仓库,用于备份和共享。 Of course, I want the remote repository to contain all of project B
, including its files ( file B₁
, file B₂
, …). 当然,我希望远程存储库包含所有的project B
,包括它的文件( file B₁
, file B₂
,...)。 But git push
and git push --recurse-submodules=on-demand
don't achieve this. 但是git push
和git push --recurse-submodules=on-demand
无法实现这一点。 Whenever I list the files in my remote repository by git ls-tree -r HEAD
, only the files of project A
itself are listed. 每当我通过git ls-tree -r HEAD
远程存储库中的文件时,只会列出project A
本身的文件。 This does make sense to me. 这对我来说确实有意义。
However, is there a way to push the entire submodule project B
to my remote base repository somehow, preferably in a clean way? 但是,有没有办法将整个子模块project B
以某种方式(最好以一种干净的方式)推送到我的远程基础存储库中?
A submodule has to have a separate repository. 子模块必须具有单独的存储库。 Create a new bare repo and push your submodule to it. 创建一个新的裸仓库,并将其子模块推送到该仓库。
If B is actually a submodule, you should have a .gitmodule referencing it. 如果B实际上是一个子模块,则应该有一个.gitmodule引用它。
In that .gitmodule
file, you would see the remote repo URL where B is pushed, in case there is any new commits done in B. 在该.gitmodule
文件中,如果在B中完成了任何新的提交,您将看到将远程回购URL推送到B的地方。
But B being a submodule means A won't have B files in it, only a reference to B SHA1. 但是B是子模块,意味着A中将没有B文件,仅是对B SHA1的引用 。
If you want, you can un-submodule B (with my answer or this one ) in order to keep all the B files in A. 如果需要,可以取消子模块B(使用我的答案或这个子模块),以便将所有B文件保留在A中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.