Created
December 2, 2009 18:01
-
-
Save dscho/247395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Finding which commits last touched the files | |
If you _need_ to know which commit gave what file its current form, this script will help you: | |
(_please_, if you try to be helpful and edit the script, make _at least_ sure that it _still runs_ (that is particularly true if you insist on adding "use strict". Yikes, I thought this goes without saying!) | |
my %attributions = (); | |
my @files = (); | |
open IN, "git ls-tree -r --full-name HEAD |" or die; | |
while (<IN>) { | |
if (/^\S+\s+blob \S+\s+(\S+)$/) { | |
$files[$#files + 1] = $1; | |
$attributions{$1} = -1; | |
} | |
} | |
close IN; | |
my $remaining = $#files + 1; | |
open IN, "git log -r --root --raw --no-abbrev --pretty=format:%h~%an~%ad~ |" or die; | |
while (<IN>) { | |
if (/^([^:~]+)~(.*)~([^~]+)~$/) { | |
($commit, $author, $date) = ($1, $2, $3); | |
} elsif (/^:\S+\s+1\S+\s+\S+\s+\S+\s+\S\s+(.*)$/) { | |
if ($attributions{$1} == -1) { | |
$attributions{$1} = "$author, $date ($commit)"; | |
$remaining--; | |
if ($remaining <= 0) { | |
break; | |
} | |
} | |
} | |
} | |
close IN; | |
for $f (@files) { | |
print "$f $attributions{$f}\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment