克隆一个包含所有子模块的 git repo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25200231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cloning a git repo with all submodules
提问by Claudio
I have a working git repository containing several submodules (obtained by cloning different repositories).
我有一个包含多个子模块的工作 git 存储库(通过克隆不同的存储库获得)。
Now, I want to copy the whole repository (with all the submodules)to a bare git repo on a different machine by either using pushing or cloning. I'm fine loosing the history of the submodules (I'm just interested in keeping their content).
现在,我想通过使用推送或克隆将整个存储库(包含所有子模块)复制到另一台机器上的裸 git存储库。我很好地失去了子模块的历史(我只是对保留它们的内容感兴趣)。
Is this possible ? In my attempts, in the cloned repository the submodule directory is empty.
这可能吗 ?在我的尝试中,在克隆的存储库中,子模块目录为空。
P.S. I know that this is not the correct workflow (see creating a public repo with submodules), however there is no possibility of updating the original submodule.
PS 我知道这不是正确的工作流程(请参阅使用子模块创建公共存储库),但是不可能更新原始子模块。
回答by
You can clone the git repo with all submodule using recursive
as follow:
您可以使用以下方法克隆所有子模块的 git repo recursive
:
git clone --recursive your-repo-url
on the other hand if you have already cloned, you can use:
另一方面,如果您已经克隆,则可以使用:
git submodule init
git submodule update
You won't lose any history in your submodule
您不会在子模块中丢失任何历史记录
回答by VonC
in the cloned repository the submodule directory is empty.
在克隆的存储库中,子模块目录为空。
If, by "cloned repo", you are referring to the bare repo, it is normal: a bare repo is always empty.
如果,通过“克隆仓库”,您指的是裸仓库,这是正常的:裸仓库始终是空的。
If you are alluding to a clone of the bare repo, you need to add:
如果您指的是裸仓库的克隆,则需要添加:
git submodule update --init --recursive
That way, you will see the content of those submodules.
这样,您将看到这些子模块的内容。
Remember, a submodule is:
请记住,子模块是:
- a declaration in a
.gitmodules
file - a gitlink entry in the index(special entry recording the SHA1 of that submodule)
.gitmodules
文件中的声明- 索引中的gitlink 条目(记录该子模块的 SHA1 的特殊条目)
So all you need to do is clone that repo (even with a --recursive
option), and the submodules will follow.
所以你需要做的就是克隆那个 repo(即使有一个--recursive
选项),子模块将随之而来。