0

我有点像 git newb 所以请在这里忍耐一下。我有一个需要刷新子模块的项目。

该项目正在使用子模块的第 1 版,并且有一些更改,所以我想升级它以使用最新版本。

如何刷新子模块并应用更改,以便克隆或从项目中提取的其他用户将使用最新的更新版本 1.5?

这是项目的外观:

ProjectA:配置为 repoA 的远程 repo 它依赖于指向 repoB 的子模块。

项目根目录中的 .git/config 文件如下所示:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@/github.com/foo/foo.git

项目根目录下还有 .gitmodules 文件:

[submodule "Vendor/some-external-library"]
        path = Vendor/some-external-library
        url = https://github.com/some-external-library/some-external-library.git

在“some-external-library”目录中,没有 .gitmodules 文件,只有带有相应文件的标准 .git 目录。.git/config 指向 repoB。

4

1 回答 1

0

子模块实际上是在你的主仓库中签出的 git 仓库,你的主仓库知道关于它们的东西,比如他们已经签出了哪个提交。

因此,您可能想要做的是转到 sumbodule 的文件夹并转到git pull origin master(或您想要拉取而不是 master 的提交),然后在您的 main 上执行一个设置反映此更改(子模块上的更改)的提交回购

简而言之:

cd submodule_dir
git pull origin master
cd main_dir
git add submodule_dir
git commit

您也可以git submodule foreach git pull按时更新所有子模块引用,但这可能是关于 repo 可维护性的一个坏主意。

更多信息在git help submodule

于 2012-07-11T00:15:31.793 回答