在對(duì)Git倉(cāng)庫(kù)進(jìn)行瘦身的時(shí)候,根據(jù)文件大小進(jìn)行排序,找到比較大的前5個(gè)文件
$ git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"
990111a0e169578b7e1cbcd99c07d11766c7ad47 aaa.sdk
ded25f77ef2b979c804453739ea20feecef175df abc.mp4
f8b6a72df3ed2825c3a25fb1deb8b2bc37ae4d1d libiPhone-lib.a
6641cbf1992ca9fa8f60ffcce746552c15c38815 bab.mp3
04df604b314823471391b6fa984f09b038487b7a voicelib.a
但這些文件對(duì)應(yīng)的哈希值都是blob,我們?nèi)绻肭袚Q到對(duì)應(yīng)commit上去查看該文件的具體情況,需要知道該blob對(duì)應(yīng)的commit的哈希值??梢酝ㄟ^(guò)以下腳本去查找:
新建一個(gè)后綴名為.pl的腳本文件git-find-blob.pl
$ vim git-find-blob.pl
然后把以下腳本放到該腳本中(源地址)
#!/usr/bin/perl
use 5.008;
use strict;
use Memoize;
# by Aristotle Pagaltzis <http://stackoverflow.com/users/9410/aristotle-pagaltzis>
# taken from thread http://stackoverflow.com/questions/223678/git-which-commit-has-this-blob
# on 6 june 2010
my $usage =
"usage: git-find-blob <blob> [<git-log arguments ...>]
pass the blob SHA1 as the first parameter
and then any number of arguments to git log
";
die $usage unless @ARGV;
my $obj_name = shift;
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';
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 );
}
把該文件拷貝到當(dāng)前Git項(xiàng)目的工作區(qū),并進(jìn)行授權(quán)
$ chmod +x git-find-blob.pl
然后輸入要查找的blob哈希值作為參數(shù)查找commit
$ ./git-find-blob1.pl ded25f77ef2b979c804453739ea20feecef175df
e63e4bc modify file
5751b59 add mp4 file
此時(shí)列表中的e63e4bc和5751b59就是和ded25f77ef2b979c804453739ea20feecef175df相關(guān)的commit了。
此時(shí)進(jìn)行git reset --hard e63e4bc 就可以看具體的情況了。