git submodule foreach checkout supermodule branch

匿名 (未验证) 提交于 2019-12-03 01:54:01

问题:

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?

回答1:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!