如何在一行中的所有子模块上 git clone --recursive 和 checkout master?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6474847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I git clone --recursive and checkout master on all submodules in a single line?
提问by tedsuo
I really like this command to fetch a repo with submodules:
我真的很喜欢这个命令来获取带有子模块的 repo:
git clone [email protected]:my_user/my_repo.git --recursive
However, the submodules are all set to "no branch" when they arrive, and I have to manually checkout master on each and every one. Is there a way to recursively pull submodules and automatically set the branch to master?
但是,子模块到达时都设置为“无分支”,我必须在每个模块上手动结帐主模块。有没有办法递归拉取子模块并自动将分支设置为master?
回答by qbein
After cloning the repository containing your submodules, the following command will checkout the master branch on all of these in one go:
克隆包含子模块的存储库后,以下命令将一次性检出所有这些的 master 分支:
git submodule foreach --recursive git checkout master
回答by Mauvis Ledford
How about:
怎么样:
git submodule update --init --recursive
To initialize all submodules and submodules inside submodules. Not sure if this will checkout master though.
初始化所有子模块和子模块内的子模块。不确定这是否会结帐大师。
回答by tcurdt
The question is whyyou checkout master. Your sub modules are pinned to a specific sha - that's also why the sub module clones are fixed to that specific commit. By not pointing to a specific sha an external repo could easily break your builds. Most definitely not what you want. Better update consciously. Builds should be reproducible and as fix as possible.
问题是你为什么要结帐大师。您的子模块固定到特定的 sha - 这也是子模块克隆固定到该特定提交的原因。通过不指向特定的 sha,外部存储库很容易破坏您的构建。绝对不是你想要的。最好有意识地更新。构建应该是可重现的并且尽可能修复。
回答by Seth Robertson
Perhaps you should consider gitslave as an alternative to git-submodule, depending on your development workflow it may be better (or worse). Specifically to your issue, gitslave keeps all members of the superproject on the same branch (absent specific git (not gitslave) commands to do otherwise, and even then many commands warn you when you are on different branches).
也许您应该考虑将 gitslave 作为 git-submodule 的替代品,这取决于您的开发工作流程,它可能会更好(或更糟)。具体到您的问题,gitslave 将超级项目的所有成员保留在同一分支上(没有特定的 git(不是 gitslave)命令来执行其他操作,即使如此,当您在不同的分支上时,许多命令也会警告您)。
Gitslaveis useful when you control and develop on the subprojects at more of less the same time as the superproject, and furthermore when you typically want to tag, branch, push, pull, etc all repositories at the same time.
当您在与超级项目更多或更少的同时控制和开发子项目时,Gitslave非常有用,此外,当您通常希望同时标记、分支、推送、拉取等所有存储库时,Gitslave非常有用。
git-submodule is better when you do not control the subprojects or more specifically wish to fix the subproject at a specific revision even as the subproject changes.
当您不控制子项目或更明确地希望在特定修订版中修复子项目时,git-submodule 会更好,即使子项目发生变化。
回答by YesThatIsMyName
As already answered
正如已经回答
git submodule foreach --recursive git checkout master
does the job for the branch master.
为分支master做这项工作。
But if it is a branch that is not present in all of the submodules one can use
但是如果它是一个不存在于所有子模块中的分支,则可以使用
git submodule foreach --recursive "git checkout branchname || true"
Otherwise the command will fail on the first repo not having the specified branch.
否则该命令将在没有指定分支的第一个 repo 上失败。