您可能想查看 Git 的子模块支持。子模块允许您将一个 git 存储库嵌入到另一个 git 存储库中。这类事情有替代解决方案,但我自己没有使用过。
一个示例可能如下所示:
$ git clone git://github.com/username/project.git
$ cd project
$ git submodule add git://github.com/username/framework.git framework
$ git commit -m "added framework submodule"
如果要克隆带有子模块的存储库,则需要使用以下--recursive
选项:
$ git clone --recursive git://<repository-with-submodules>.git
或者,您可以定期克隆,然后运行:
$ git submodule init
$ git submodule update
阅读链接文档(和git submodule --help
)了解更多信息。
如果对子模块进行了更改,您可以像这样将它们引入:
# first update the submodule just like any other git repository
$ cd project/framework
$ git pull
# now you have to record the new commit in the parent repository
$ cd ..
$ git commit -m "updated framework submodule"
最后一步是必要的,因为 git 会记录与给定子模块关联的特定提交(这样当任何人克隆父模块时,他们将获得该子模块的版本,而不是其最新版本,这可能已经经历了破坏性的更改,这将阻止它按预期与父存储库一起工作)。所以如果你更新子模块,你需要在父模块中记录新的提交。
如果您在framework
子模块中进行更改,您将再次git push
像对任何其他存储库一样进行更改。然后,您必须在父模块中提交新修订。