根据 此 GitHub 问题:
# run git submodule update and the && makes sure init is only ran if the first worked
git submodule update && git submodule init
# https://github.com/UCSD-PL/proverbot9001/issues/73#issue-1570685156
但是,我相信以下是正确的,或者更安全,或者标准的方式:
# - git submodule init initializes your local configuration file to track the submodules your repository uses, it just sets up the configuration so that you can use the git submodule update command to clone and update the submodules.
git submodule init
# - The --remote option tells Git to update the submodule to the commit specified in the upstream repository, rather than the commit specified in the main repository. ref: https://stackoverflow.com/questions/74988223/why-do-i-need-to-add-the-remote-to-gits-submodule-when-i-specify-the-branch?noredirect=1&lq=1
git submodule update --init --recursive --remote
# - for each submodule pull from the right branch according to .gitmodule file. ref: https://stackoverflow.com/questions/74988223/why-do-i-need-to-add-the-remote-to-gits-submodule-when-i-specify-the-branch?noredirect=1&lq=1
git submodule foreach -q --recursive 'git switch $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master || echo main )'
# - check it's in specified branch. ref: https://stackoverflow.com/questions/74998463/why-does-git-submodule-status-not-match-the-output-of-git-branch-of-my-submodule
git submodule status
我说得对吗?
r/git
。
UCSD-PL/proverbot9001
存储库,引用很多子模块(参见 its .gitmodules
文件)的一个更简单的说明是仅使用 git clone --recurse-submodules
选项:
这将完成所有操作:克隆父存储库,初始化所有子模块并更新它们。一气呵成。
正如“'
git submodule init
'的意义是什么?”中所解释的,当您不想要所有子模块时,分开这两个步骤(初始化和更新)是有意义的(因为这会花费太多时间/资源来克隆它们),并且只想在一个子集上工作。
在这种情况下,是的,init 必须在更新之前出现。
这来自 commit be4d2c8,Git v1.5.6-rc0,2008 年 5 月
:添加便利选项submodule update
--init
当子模块未初始化并且您不想更改子模块时 无论如何,默认为
,你现在可以说.gitmodules
$ git submodule update --init <name>
当在未初始化的子模块上调用“
”而不使用update
时,会打印使用--init
的提示。--init