Git子模块来跟踪远程分支 [英] Git submodule to track remote branch

查看:181
本文介绍了Git子模块来跟踪远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



它应该克隆模块并签出分支。

我试图使用git子模块将10个以上的存储库聚合到一个结构中,以便于开发。
取而代之的是,模块以分离头模式签出。

  git clone git@github.com:org / global-repository.git 
git子模块更新-init $ b $ cd配置框架
git状态

$ git状态
#HEAD在b932ab5分离
没有提交,工作目录干净

gitmodules文件似乎没问题

  $ cat .gitmodules 
[submoduleconfig-framework]
path = config-framework
url = git @ github.com:org / config-framework.git
branch = MY_BRANCH

我们想要MY_BRANCH分支默认检出,而不是分离头。
我们如何实现这一点?

解决方案

子模块始终 strong> 分离HEAD模式



是因为子模块将检出存储在 父回购的索引中的特殊条目中的SHA1



另外,如果您希望子模块遵循您在 .gitmodules 中注册的分支,您需要:

  git submodule update --init --remote 
$ b

- remote 将会产生 git fetch ,加上新的 HEAD 的结帐。

Alas,即使是结账也是提交,而不是分支(因为你没有本地分支默认情况下在一个子模块中),所以...返回到分离的 HEAD 模式。

请参阅 Git submodules:指定分支/标记



您可以尝试(未经测试)a:

  git submodule foreach'git checkout -b $(git config -f /path/to/parent/repo/.gitmodules --get submodule。 $ path.branch)'

我利用事实 git submodule foreach 可以访问' $ path ',子模块目录相对于超级项目的名称。






有人试图指定一个子模块的分支在(提交23d25e4 为Git 2.0)....但它得到颠倒( commit d851ffb ,2014年4月2日)!
它可能会很快出现,但不会在当前的实施中。


I'm trying to use git submodules for aggregating 10+ repositories into one structure for easy development.

It is supposed to clone the module and checkout a branch. Instead, the module is checked out in detached head mode.

git clone git@github.com:org/global-repository.git
git submodule update —init
cd config-framework
git status

$git status
#HEAD detached at b932ab5
nothing to commit, working directory clean

gitmodules files seems to be okay

$cat .gitmodules 
[submodule "config-framework"]
        path = config-framework
        url = git@github.com:org/config-framework.git
        branch = MY_BRANCH

We want the MY_BRANCH branch to be checked out by default, rather than detached head. How do we achieve that?

解决方案

Submodules are always checked out in a detached HEAD mode.

That is because a submodule will checkout the SHA1 stored in the special entry in the index of the parent repo.

Plus, if you want a submodule to follow the branch you have registered in the .gitmodules, you need:

git submodule update --init --remote

The --remote will make a git fetch, plus a checkout of the new HEAD.
Alas, even that checkout will be of a commit, not of the branch (since you have no local branch by default in a submodule), so... back to a detached HEAD mode.
See more at "Git submodules: Specify a branch/tag".

You can try (not tested) a:

git submodule foreach 'git checkout -b $(git config -f /path/to/parent/repo/.gitmodules --get submodule.$path.branch)'

I take advantage of the fact git submodule foreach has access to '$path', the name of the submodule directory relative to the superproject.


There was an attempt to specify a branch for a submodule to be automatically checked out in (commit 23d25e4 for Git 2.0).... but it got reversed (commit d851ffb, April 2d 2014)!
It might come soon, but not in its current implementation.

这篇关于Git子模块来跟踪远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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