哪个提交有这个小斑点?给定BLOB的散列,是否有一种方法可以获得在其树中包含此BLOB的提交列表?
3 回答
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
git log--all-g
#!/bin/shobj_name="$1"shift git log "$@" --pretty=format:'%T %h %s' \| while read tree commit subject ; do if git ls-tree -r $tree | grep -q "$obj_name" ; then echo $commit "$subject" fidone
#!/usr/bin/perluse 5.008;use strict;use Memoize;my $obj_name;sub check_tree {
my ( $tree ) = @_;
my @subtree;
{
open my $ls_tree, '-|', git => 'ls-tree' => $tree
or die "Couldn't open pipe to git-ls-tree: $!\n";
while ( <$ls_tree> ) {
/\A[0-7]{6} (\S+) (\S+)/
or die "unexpected git-ls-tree output";
return 1 if $2 eq $obj_name;
push @subtree, $2 if $1 eq 'tree';
}
}
check_tree( $_ ) && return 1 for @subtree;
return;}memoize 'check_tree';die "usage: git-find-blob <blob> [<git-log arguments ...>]\n"
if not @ARGV;my $obj_short = shift @ARGV;$obj_name = do {
local $ENV{'OBJ_NAME'} = $obj_short;
`git rev-parse --verify \$OBJ_NAME`;} or die "Couldn't parse $obj_short: $!\n";chomp $obj_name;open my $log, '-|',
git => log => @ARGV, '--pretty=format:%T %h %s'
or die "Couldn't open pipe to git-log: $!\n";while ( <$log> ) {
chomp;
my ( $tree, $commit, $subject ) = split " ", $_, 3;
print "$commit $subject\n" if check_tree( $tree );}
心有法竹
TA贡献1866条经验 获得超5个赞
git log --all --pretty=format:%H -- <path> | xargs -n1 -I% sh -c "git ls-tree % -- <path> | grep -q <hash> && echo %"
胡说叔叔
TA贡献1804条经验 获得超8个赞
#!/usr/bin/perl -wuse strict;my @commits;my %trees;my $blob;sub blob_in_tree {
my $tree = $_[0];
if (defined $trees{$tree}) {
return $trees{$tree};
}
my $r = 0;
open(my $f, "git cat-file -p $tree|") or die $!;
while (<$f>) {
if (/^\d+ blob (\w+)/ && $1 eq $blob) {
$r = 1;
} elsif (/^\d+ tree (\w+)/) {
$r = blob_in_tree($1);
}
last if $r;
}
close($f);
$trees{$tree} = $r;
return $r;}sub handle_commit {
my $commit = $_[0];
open(my $f, "git cat-file commit $commit|") or die $!;
my $tree = <$f>;
die unless $tree =~ /^tree (\w+)$/;
if (blob_in_tree($1)) {
print "$commit\n";
}
while (1) {
my $parent = <$f>;
last unless $parent =~ /^parent (\w+)$/;
push @commits, $1;
}
close($f);}if (!@ARGV) {
print STDERR "Usage: git-find-blob blob [head ...]\n";
exit 1;}$blob = $ARGV[0];if (@ARGV > 1) {
foreach (@ARGV) {
handle_commit($_);
}} else {
handle_commit("HEAD");}while (@commits) {
handle_commit(pop @commits);}git ls-tree -r
- 3 回答
- 0 关注
- 481 浏览
添加回答
举报
0/150
提交
取消
