gpt4 book ai didi

git submodule foreach checkout supermodule 分支

转载 作者:太空狗 更新时间:2023-10-29 14:44:54 27 4
gpt4 key购买 nike

考虑一个 git 存储库 Foo/,它有子模块 bar1/和 bar2/。

其中每一个都有相同的分支:1 和 2。

我进入 super 模块,我想更新 super 模块以包含来自 bar1 和 bar2 源的最新提交。我已经初始化并更新了 super 模块,因此 bar1 和 bar2 中有工作树,但它们处于分离状态。我可以执行以下操作:

cd foo;
git checkout 1
git submodule foreach git checkout 1
git pull

现在,让我烦恼的是重复分支标识符。我可以做类似“git submodule foreach git checkout $CURRENT_BRANCH_ID”这样的事情吗?有更好的选择吗?

最佳答案

子模块默认总是in detached HEAD mode .

您可以让每个子模块跟随一个分支。
参见“How to make an existing submodule track a branch”。

cd /path/to/your/parent/repo/Foo
git config -f .gitmodules submodule.bar1.branch branch1
git config -f .gitmodules submodule.bar2.branch branch2

那么你需要做的就是:

git submodule update --remote

这会将每个子模块更新到各自上游分支的最新版本(获取 + checkout )。

关于git submodule foreach checkout supermodule 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33894897/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com