summaryrefslogtreecommitdiffstats
path: root/gitBlameFromLineNo
diff options
context:
space:
mode:
Diffstat (limited to 'gitBlameFromLineNo')
-rwxr-xr-xgitBlameFromLineNo24
1 files changed, 24 insertions, 0 deletions
diff --git a/gitBlameFromLineNo b/gitBlameFromLineNo
new file mode 100755
index 0000000..432e3fa
--- /dev/null
+++ b/gitBlameFromLineNo
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use v5.10;
+
+my $debug = 0;
+
+my $line_no = $ARGV[0];
+my $file_name = $ARGV[1];
+say "Line: $line_no | File: $file_name" if $debug;
+
+# Get the git blame for the line & file
+my $line = `git blame -L $line_no,$line_no $file_name`;
+say "Line: $line" if $debug;
+
+# Reduce this just to the SHA
+chomp $line;
+(my $sha = $line) =~ s/^(\S+).*/$1/;
+say "SHA: $sha" if $debug;
+
+# Show the commit for that SHA
+system("git show $sha"); \ No newline at end of file