如何在一行中对所有子模块执行 git clone --recursive 和 checkout master 操作?

发布于 2024-11-17 05:57:32 字数 303 浏览 5 评论 0原文

我真的很喜欢这个命令来获取带有子模块的存储库:

git clone [email protected]:my_user/my_repo.git --recursive

但是,子模块到达时都设置为“无分支”,我必须手动检查每个子模块的主模块。有没有办法递归拉取子模块并自动将分支设置为master?

I really like this command to fetch a repo with submodules:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最美不过初阳 2024-11-24 05:57:32

克隆包含子模块的存储库后,以下命令将一次性检出所有这些子模块的主分支:

git submodule foreach --recursive git checkout master

After cloning the repository containing your submodules, the following command will checkout the master branch on all of these in one go:

git submodule foreach --recursive git checkout master
只怪假的太真实 2024-11-24 05:57:32

怎么样:

git submodule update --init --recursive

初始化所有子模块以及子模块内的子模块。不确定这是否会结帐大师。

How about:

git submodule update --init --recursive

To initialize all submodules and submodules inside submodules. Not sure if this will checkout master though.

风吹雨成花 2024-11-24 05:57:32

问题是为什么你结帐大师。您的子模块固定到特定的 sha - 这也是子模块克隆固定到该特定提交的原因。如果不指向特定的 sha,外部存储库很容易破坏您的构建。绝对不是你想要的。最好有意识地更新。构建应该是可重复的并且尽可能修复。

The question is why you 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.

川水往事 2024-11-24 05:57:32

正如已经回答的那样,

git submodule foreach --recursive git checkout master

分支的工作是master

但如果它是一个并不存在于所有子模块中的分支
可以使用

git submodule foreach --recursive "git checkout branchname || true"

否则该命令将在第一个没有指定分支的存储库上失败。

As already answered

git submodule foreach --recursive git checkout master

does the job for the branch 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.

尝蛊 2024-11-24 05:57:32

也许您应该考虑将 gitslave 作为 git-submodule 的替代品,具体取决于您的开发工作流程,它可能会更好(或更差)。具体到您的问题,gitslave 将超级项目的所有成员保留在同一分支上(没有特定的 git (不是 gitslave)命令来执行其他操作,即使这样,当您位于不同的分支上时,许多命令也会警告您)。

当您与超级项目同时控制和开发子项目时,以及当您您通常希望同时对所有存储库进行标记、分支、推送、拉取等。

当您不控制子项目或更具体地希望在特定修订版中修复子项目(即使子项目发生更改)时,git-submodule 会更好。

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 is 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文