我会推荐 android 使用的 repo 工具。它足够通用,可以与任何 git 托管环境一起使用,并且不需要像子模块那样需要超级项目提交来更新子项目。
首先,按照此处所述安装客户端:https://source.android.com/source/downloading.html#installing-repo
然后创建一个清单存储库。清单是一个 xml 文件,它描述了 git 存储库位置和它们应该被签出的路径。像这样:
mkdir manifests
cd manifests
git init
创建清单文件default.xml:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="github" fetch="ssh://git@github.com" />
<default remote="github" revision="master" />
<project name="git/git.git" path="git" />
<project name="libgit2/libgit2.git" path="vendor/libgit2" />
</manifest>
然后添加、提交清单,然后推送到某处:
git add default.xml
git commit -m "My first try at a manifest file"
git push git@github.com:myusername/manifests.git master
现在您可以使用repo 命令了。
mkdir myproject
cd myproject
repo init -u git@github.com:myusername/manifests.git
repo sync -j2
您的 git 存储库将被克隆。您现在可以像往常一样在每一个中工作。在您推送到任何项目后,其他人只需发送repo sync,它们就会更新到最新版本(另请参阅repo start)。
注意事项
您可能需要重新组织您的项目。通常,您可能会将其他模块作为子目录 (myproject/vendor/dependency)。虽然您仍然可以使用 repo 维护此布局,但它会导致 git 存储库与另一个 repo 签出。使用 .gitignore 诡计它可能是可行的,但我建议重新组织您的项目,这样存储库就不需要相互签出。
清单文件的简短说明
有关 xml 文件中每个项目的完整说明,请参阅https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt。
查看https://source.android.com/source/using-repo.html 以获得简单的命令参考。 repo help 也很有用。注意:除非您使用 Gerrit,否则您应该忽略 repo upload。
<remote name="github" fetch="ssh://git@github.com" />
这就像在git 中添加一个遥控器。这意味着我们可以使用给定名称引用 url。
<default remote="github" revision="master" />
默认元素指定项目的默认选项。这相当于在每个项目上添加 remote 和 revision 项目。这只是节省了一些输入。
<project name="git/git.git" path="git" />
这是真正的工作发生的地方。 repo sync 将获取名称并使用斜杠将其附加到远程。在这种情况下,遥控器是默认的github,所以它会得到 url ssh://git@github.com/git/git.git。它会将项目签出到指定修订版的路径git(在这种情况下,默认值为master)。随后的repo syncs 将检出最新版本(在分支的情况下)。