如何在git repo中找到blob的所有用途 [英] How to find all uses of a blob in a git repo

查看:77
本文介绍了如何在git repo中找到blob的所有用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在(本地)git存储库中拥有blob对象的SHA-1对象哈希.我需要以commit-id,路径名和文件名的形式找到所有用途,例如生成所有可能的git show命令,这些命令将打印我的blob内容:

I have the SHA-1 object hash of a blob object in a (local) git repository. I need to find all uses in the form of commit-id, pathname and filename, e.g. generating all possible git show commands that would print the contents my blob:

git show <commit-id1>:foo/bar/baz.txt
git show <commit-id1>:README.txt
git show <commit-id2>:foo/quux.txt

推荐答案

我可以使用git log查找我关心的所有提交,然后使用git ls-tree -r查找提交中的所有blob,然后使用Perl只保留我感兴趣的斑点:

I can use git log to find all commits I care about, and then use git ls-tree -r to find all the blobs in a commit, and then use Perl to keep only the blobs I'm interested in:

for COMMITID in `git log --pretty=format:%H`; do
  git ls-tree -r "$COMMITID" | perl -we '
      use integer; use strict; my $commitid = $ARGV[0]; my $f;
      die if !open($f, "<", "blobid.lst");
      my %h = map { s@\s.*@@s; $_ ? ($_=>1) : () } <$f>;
      while (<STDIN>) {
        die "bad: $_\n" if !s@^\S+\sblob\s([0-9a-f]{40})\t@@;
        my $blobid=$1;
        chomp;
        print "git show \x27$commitid:$_\x27\n" if $h{$blobid} }' -- "$COMMITID"
done

我感兴趣的Blob ID列表存储在文件blobid.lst中,每行一个ID.

The list of the blob IDs I'm interested in are stored in the file blobid.lst, one ID per line.

这篇关于如何在git repo中找到blob的所有用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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