git submodule foreach结帐超模块分支 [英] git submodule foreach checkout supermodule branch

查看:132
本文介绍了git submodule foreach结帐超模块分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个git仓库Foo /,它有子模块bar1 /和bar2 /.



每个分支都有相同的分支:1& 2。

我输入超模块,我想更新超模块以包含来自bar1和bar2原点的最新提交。我已经启动并更新了supermodule,因此bar1和bar2中有工作树,但它们处于分离状态。我可以做到以下几点:

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



<现在,我错过了重复分支标识符。我可以做一些像git submodule foreach git checkout $ CURRENT_BRANCH_ID吗?有没有更好的选择?

解决方案

子模块始终默认为在分离的HEAD模式下。



您可以让每个子模块遵循分支。

请参阅 a href =https://stackoverflow.com/a/18799234/6309>如何让现有子模块跟踪分支

  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 

将每个子模块更新到它们各自上游分支的最新版本(fetch + checkout)。


Consider a git repository Foo/, which has submodules bar1/ and bar2/.

Each of these has the same branches: 1 & 2.

I enter the supermodule, and I want to update the supermodule to contain the most recent commits from bar1 and bar2's origin. I've already init'd and updated the supermodule, so there's working trees in bar1 and bar2, but they are in a detached state. I can do the following:

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

Now, what bugs me is repeating the branch identifier. Can I do something like "git submodule foreach git checkout $CURRENT_BRANCH_ID"? Is there a better alternative?

解决方案

A submodule is always by default in detached HEAD mode.

You can make each submodule follow a branch.
See "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

Then all you need to do is:

git submodule update --remote

That will update each submodule to the latest of their respective upstream branch (fetch + checkout).

这篇关于git submodule foreach结帐超模块分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆