要将子模块添加到 git 仓库中,请执行以下步骤:
- 执行
git submodule add
命令,加上你想要添加的子模块仓库的 URL,以及存储子模块的路径。例如:
git submodule add https://github.com/user/repo.git submodules/repo
这将在当前目录下创建一个名为 submodules/repo
的文件夹,并将指定的仓库 clone 到该文件夹中。
- 提交更改。执行
git commit
命令,提交你刚刚添加的子模块。
git commit -m "Add submodule repo"
- 推送更改。如果你正在使用远程 git 仓库,则需要执行
git push
命令将新提交推送到远程仓库。
git push
现在,你已经成功地将一个子模块添加到你的 git 仓库中了!