git - 列出使用特定子模块的存储库

标签 git git-submodules

我有几个 git 存储库(项目),它们使用其他存储库(“组件”)作为子模块:

Project 1
 - Component A
 - Component B
Project 2
 - Component B
 - Component C
Project 3
 - Component A
 - Component B

所有存储库并排在同一台服务器上:

 - Project 1
 - Project 2
 - Project 3
 - Component A
 - Component B
 - Component C

我想知道在哪个项目中使用了组件B。更具体:在哪个项目中使用了组件 B 的特定提交 - 或其后代。

我的方法:创建一个包含所有子模块的数据库来存储它们的提交哈希值。然后遍历特定提交的所有父项并查看它们是否在数据库中。

您是否知道更好的解决方案,也许只使用 git 命令?

您知道(部分)解决我的问题的应用程序/项目/库吗?

最佳答案

嗨,我今天为一位同事制作了小脚本 那想知道给定子模块的哪些“版本”用于 super 模块中的所有 sha1。

#!/bin/perl

use strict;
use warnings;

my $command = "";
my $submodule = $ARGV[0];
my $submodule_sha = "";
my @commits = ();
my %commit_hash = ();
my $commit = "";
my $key = "";
my $value = "";
$command="git log --since=\"1 week ago\" --format=format:%H";
@commits=`$command`;
foreach $commit (@commits)
{
    #cleaning the $commit
    $commit =~ s/\s+$//;
    $commit =~ s/^\s+//;
    $command="git ls-tree $commit \| grep $submodule \|  cut -d\" \" -f3 |cut -f1";
    print $command . "\n";
    $submodule_sha=`$command`;
    $commit_hash{$commit} = $submodule_sha;
}    

while (($key, $value) = each(%commit_hash)){
    print $key.", ".$value."\n";
}

这样执行

你应该在 super 模块中

./scriptname.pl 子模块名

基本上我只是利用 git ls-tree 命令 如果你在 super 模块中,你可以做 git ls-tree 头 | grep“子模块名” 这将为您提供子模块的提交。

可能有更聪明的方法,但这可以解决问题:)

干杯

关于git - 列出使用特定子模块的存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12314137/

相关文章:

git - 授予对 github 上单个文件的访问权限

git - 如何更改 git 子模块的远程存储库?

git - 如果在 git 中使用 hook 存在 Unresolved 冲突,如何防止推送?

如果我有本地更改,有时允许 git checkout 实验,有时则不允许

git-tfs 本地 Git repo 到 TFVC

javascript - 从不同目录运行早午餐并使用相对路径

windows - 将 Github 远程添加到 GitKraken

git - 为每次提交获取 git 存储库的准确总行数

git - 带有私有(private)子模块的Azure github部署

git - 是否可以将子模块文件夹内的文件添加到父 GIT 存储库?