git - 如何将 Git 子模块指针恢复为存储在包含存储库中的提交?

标签 git git-submodules

我的主 git 仓库中有一个 git 子模块。据我了解,主 repo 存储一个 SHA 值(某处......),指向它“链接到”的子模块的特定提交。

我进入我的子模块并输入 git checkout some_other_branch。我不知道我来自哪个提交。

我想还原该指针,以便主仓库和子模块再次同步。

我的第一个(可能是天真的)直觉是说 git reset --hard - 这似乎适用于其他一切。令我惊讶的是,它不适用于这种情况。

所以我发现我可以输入 git diff,记下子模块指针曾经拥有的 SHA ID,然后进入子模块并 git checkout [SHA ID ]...但是一定有更简单的方法吗?

由于我仍在学习 git 子模块,如果有我不知道的概念词,请随时纠正我的术语。

最佳答案

您想更新您的子模块,使其与父存储库认为应该的同步。这就是更新命令的用途:

来自子模块联机帮助页:

Update the registered submodules, i.e. clone missing submodules and
checkout the commit specified in the index of the containing
repository. This will make the submodules HEAD be detached unless
--rebase or --merge is specified or the key submodule.$name.update
is set to rebase or merge.

Run this and all should be well:

git submodule update --init

您也可以添加 --recursive 标志以递归遍历所有子模块。

关于git - 如何将 Git 子模块指针恢复为存储在包含存储库中的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7882603/

相关文章:

git - 无法 checkout git 子模块路径

git - 更新 Git 子模块失败

Github 多个帐户-personalUserName/repoName.git 的权限被拒绝给 globalUserName

git - 忽略 git diff 中的 merge

Git别名删除远程分支

git - 如何防止 git 要求我提交子模块修改

git - git bundle 应该如何与子模块一起工作?

git - 无法访问远程存储库以导入 Go 模块

git - 是否可以在不 pull 文件的情况下检查 DVC 元数据文件跟踪的文件版本是否存在于远程存储中?

django - 为项目框架创建一个 git repo