获取另一个目录中的git子模块的分支名称

问题描述 投票:0回答:1

我检查了一个包含一些子模块的项目。

首先,我检查了我的project然后submodules

git clone git@my-gitlab-server:namespace/project.git

使用最新版本启动了branch的子模块:

git submodule update --init --recursive

然后我检查了包含子模块的特定分支。我只想获得每个sumbodule的分支名称。

但:

$ git --git-dir path/to/my/submodule rev-parse --abbrev-ref HEAD
fatal: not a git repository: 'path/to/my/submodule'


$ cd  path/to/my/submodule 
$ (detached*)$ git branch
* (HEAD detached at 24bbc55)
  develop

为什么第一个命令显示它不是git子模块? (虽然它是)结账是从子模块的特定分支('develop')完成的。我怎样才能获得实际的分支名称(而不是git sha?)

git git-submodules
1个回答
0
投票

从项目列表中,git存储库中每个子模块的分支名称和状态:

git submodule foreach 'git status'

从子模块列表中,该子模块的分支名称

git branch

git子模块的分离状态的原因可以在另一个问题中找到:stackoverflow.com/a/48556186/3564632

© www.soinside.com 2019 - 2024. All rights reserved.