git - 将克隆的 git 存储库转换为子模块

标签 git git-submodules

我有一个 git 存储库项目,在该项目中我有一些克隆的 git 存储库。

目录结构是这样的。

main-project
    -other_project (cloned git repository)
    -another_project (cloned git repository)

当我尝试将主项目克隆到另一个系统时,它只有 other_project 和 another_project 的空目录。

我知道我应该首先使用 git submodule 来添加这些存储库。既然我没有,有什么办法可以解决我造成的困惑吗?

内部大约有 15 个存储库(应该是子模块),因此,如果有一种将所有这些存储库“批量转换”为子模块的方法,我们将不胜感激。

最佳答案

您需要创建一个脚本,有点像“How to do a bash foreach csv field to 'git submodule add' ”,但对于每个嵌套存储库,您需要提取上游存储库 URL ( git remote origin )

然后添加 "submodule add" 在您的父存储库中创建的 .gitmodules 文件,然后提交。

您将能够clone (使用 --recursive 选项)您的父存储库,并取回所有这些子模块。

关于git - 将克隆的 git 存储库转换为子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14554878/

相关文章:

git - Jira Smart 提交未运行的命令

git - 致命的 : NullReferenceException encountered when interacting with remote

git - git push 如何处理积压的工作

git - 如何删除 Azure Git 推送历史记录?

git-submodules - Git 子模块 : Cannot update submodule to an earlier revision

git 子模块替换不会分离头

git - 如何在 Github 中将单独的 pull 请求与 "stacking"相互叠加?

git - 如何公开使用子模块,但符号链接(symbolic link)到本地​​的单个克隆?

git - Heroku 推送被拒绝,子模块安装失败

git - 如何 pull 一个新的子模块