Here is a Perl script that prints out Git diff commands for a given file as found in a Git log command.
E.g.
git log pom.xml | perl gldiff.pl 3 pom.xml
Yields:
git diff 5cc287:pom.xml e8e420:pom.xml
git diff 3aa914:pom.xml 7476e1:pom.xml
git diff 422bfd:pom.xml f92ad8:pom.xml
which could then be cut and pasted in a shell window session or piped to /bin/sh
.
Notes:
- the number (3 in this case) specifies how many lines to print
- the file (pom.xml in this case) must agree in both places (you could wrap it in a shell function to provide the same file in both places) or put it in a binary directory as a shell script
Code:
# gldiff.pl
use strict;
my $max = shift;
my $file = shift;
die "not a number" unless $max =~ m/\d+/;
die "not a file" unless -f $file;
my $count;
my @lines;
while (<>) {
chomp;
next unless s/^commit\s+(.*)//;
my $commit = $1;
push @lines, sprintf "%s:%s", substr($commit,0,6),$file;
if (@lines == 2) {
printf "git diff %s %s\n", @lines;
@lines = ();
}
last if ++$count >= $max *2;
}