我的主 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/