Git:如何处理项目中的git库

dhr*_*hrm 21 git github

我有一个Xcode项目,它本身就有Git Source Control.在Libraries文件夹中,我从GitHub克隆了另外八个Git项目.它们位于我自己的Git存储库中,我在提交中将所有这些库添加到我的git中.

而不是在我的存储库中拥有所有这些git库的代码,有没有办法让git在我的repo克隆时从他们的repo下载他们的代码?或者在项目中包含其他git repos是否正常?

Bes*_*esi 27

当然要做以下事情:

  1. 删除您可能已添加的第三方文件夹
  2. 打开终端并执行以下命令

    cd /path/to/your/main/repo
    git submodule add git@github.com:someuser/somerepo.git somerepo
    git commit -m "Added submodules"
    
    Run Code Online (Sandbox Code Playgroud)
  3. 现在,您不必复制这些文件,而是引用项目中的其他存储库:

编辑:

现在,如果要将子模块更新为更新的提交,可以执行以下操作:

cd somerepo
git pull # You can also checkout a branch / tag etc.
cd ..
git add somerepo
git commit -m "Telling the main repo to update the reference to the referenced repo"
Run Code Online (Sandbox Code Playgroud)