如何将Git Submodule指针恢复到存储在存储库中的提交? [英] How to revert a Git Submodule pointer to the commit stored in the containing repository?
问题描述
在我的主git仓库中有一个git子模块。据我了解,主repo存储SHA值(某处......),指向子模块的链接到的特定提交。
我进入了我的子模块并输入 git checkout some_other_branch
。我不知道我来自哪个提交。
我想要恢复该指针,以便主repo和子模块再次同步。 b
$ b
我的第一个(可能是天真的)本能是说 git reset --hard
- 这似乎适用于其他任何事情。令我惊讶的是,它并不适用于这种情况。
所以我发现我可以输入 由于我仍然在学习git子模块,如果有我不知道的概念的话,请随时更正我的术语。您需要更新您的子模块,以便它与父仓库认为它应该是什么相同步。解决方案 git diff $ c $请注意子模块指针所使用的SHA标识,然后进入子模块并
git checkout [SHA ID]
...但肯定必须有一个更简单的方法?
这是更新命令的用途:
从子模块手册页:
更新已注册的子模块,即克隆缺少的子模块,
签出包含
存储库的索引中指定的提交。除非指定了
--rebase或--merge,否则子模块HEAD将被分离,或者将键子模块$ name.update
设置为rebase或merge。
运行此操作,所有操作都应该顺利:
git子模块更新
I have a git submodule in my main git repo. As I understand it, the main repo stores a SHA value (somewhere...), pointing to the specific commit of the submodule that it is "linked to".
I went in to my submodule and typed git checkout some_other_branch
. I have no idea which commit I came from.
I would like to revert that pointer so that the main repo and the submodule are in sync again.
My first (probably naive) instinct was to say git reset --hard
- that seems to work for everything else. To my surprise, it did not work for this scenario.
So I've figured out that I can type git diff
, note the SHA ID that the submodule pointer used to have, and then head into the submodule and git checkout [SHA ID]
... but surely there must be an easier way?
As I'm still learning about git submodules, please feel free to correct my terminology if there are words for concepts that I don't know.
You want to update your submodule so it is in sync with what the parent repository believes it should be. This is what the update command is for:
From the submodule manpage:
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
这篇关于如何将Git Submodule指针恢复到存储在存储库中的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!