2015-10-19 53 views
0

我在(本地)git倉庫中擁有blob對象的SHA-1對象哈希值。我需要以commit-id,路徑名和文件名的形式查找所有用途,例如生成將打印內容我一滴都可能git show命令:如何在git倉庫中查找blob的所有用法

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

我想爲了得到這些信息,你需要遍歷所有的提交,然後(遞歸地)遍歷所有的樹並檢查一個blob id是否與你的hash匹配。由於如何構建Git對象樹,我不認爲有任何其他方法。 – poke

回答

1

我可以使用git log找到我關心所有提交,然後用git ls-tree -r找到一個提交所有的斑點,然後使用Perl只保留斑點我很感興趣:

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 { [email protected]\s.*@@s; $_ ? ($_=>1) :() } <$f>; 
     while (<STDIN>) { 
     die "bad: $_\n" if [email protected]^\S+\sblob\s([0-9a-f]{40})\[email protected]@; 
     my $blobid=$1; 
     chomp; 
     print "git show \x27$commitid:$_\x27\n" if $h{$blobid} }' -- "$COMMITID" 
done 

斑的ID我感興趣的是存儲在文件中blobid.lst的名單,每行一個ID。

相關問題