Cloning a git repo with all submodules

被刻印的时光 ゝ 提交于 2019-12-03 05:55:21

问题


I have a working git repository containing several submodules (obtained by cloning different repositories).

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

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.


回答1:


You can clone the git repo with all submodule using recursive as follow:

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




回答2:


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)

So all you need to do is clone that repo (even with a --recursive option), and the submodules will follow.



来源:https://stackoverflow.com/questions/25200231/cloning-a-git-repo-with-all-submodules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!