admin管理员组文章数量:1418113
I am trying to clone a git repo and checkout a particular tag. But I have a doubt regarding the order of commands. For now, I follow these steps:
git clone <some_repo>
cd <repo_dir>
git submodule update --init
git checkout tags/tag_001
When checking out an old tag, should one update the submodule before checking out or after?
Thanks.
I am trying to clone a git repo and checkout a particular tag. But I have a doubt regarding the order of commands. For now, I follow these steps:
git clone <some_repo>
cd <repo_dir>
git submodule update --init
git checkout tags/tag_001
When checking out an old tag, should one update the submodule before checking out or after?
Thanks.
Share Improve this question edited Feb 3 at 7:26 dani-vta 7,5357 gold badges49 silver badges65 bronze badges asked Jan 31 at 9:13 QTipQTip 948 bronze badges 1- The only time I think the order of operations would have an effect, is if the submodule existed at both the current HEAD and the tag youre checking out. If so, then the order shouldnt matter – Michael Commented Jan 31 at 11:19
1 Answer
Reset to default 2The first git submodule update --init
after the clone is necessary only to create and initialize the submodules contained in your repository. Alternatively, you could perform a git clone --recurse-submodules <some_repo>
to compact the process into a single command.
After the clone is created, initialize and clone submodules within based on the provided <pathspec>. If no=<pathspec> is provided, all submodules are initialized and cloned.
When you checkout another commit (via a tag in your case), you need to run a second git submodule update
to update the content of the submodule according to the commit recorded in the superproject. In fact, tag_001
may refer to a commit that recorded the submodule at commit X
, while the branch you've checked out after the clone could refer to a commit that recorded the submodule at commit Y
. If you checkout tag_001
without running git submodule update
afterward, the submodule would still be checked out at commit Y
, even though it should be at commit X
.
Update the registered submodules to match what the superproject expects by cloning missing submodules, fetching missing commits in submodules and updating the working tree of the submodules.
The explanation above was done assuming that you had a single submodule with no nested submodules. If that is not the case, you should add the options --init
and --recursive
to both your git submodule update
. This is because the first update needs to recursively initialize every submodule recorded in the commit checked out after the clone. While the second update is necessary because the commit you're switching to might contain some other (nested) submodules that are not present in the commit currently checked out. Therefore, they need to be recursively initialized.
The previous writings (git checkout
and git submodule update
) can be compacted into a single command with git checkout --recurse-submodules tags/tag_001
.
Using --recurse-submodules will update the content of all active submodules according to the commit recorded in the superproject.
本文标签: gitDoes updating the submodules before checking out a tag have any adverse effectsStack Overflow
版权声明:本文标题:git - Does updating the submodules before checking out a tag have any adverse effects? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745272813a2650997.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论