Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Created January 28, 2013 18:15
Show Gist options
  • Save carlosmcevilly/4657754 to your computer and use it in GitHub Desktop.
Save carlosmcevilly/4657754 to your computer and use it in GitHub Desktop.
extract two git commit hashes out of the pasteboard and do a git diff on them
#!/usr/bin/perl
# extract two git commit hashes out of the pasteboard and do a git diff on them.
#
# no need to clean up any extra stuff in the paste -- this will do a diff of the
# top-most and bottom-most hashes found in the paste.
#
# requires pbpaste command line utility
use strict;
use warnings;
my $data = `pbpaste`;
my @data = split(/[\n\r]+/, $data);
my ($top,$bot);
foreach my $line (@data) {
if ($line =~ /commit ([a-f0-9]{40})/) {
my $match = $1;
if (!defined($top)) {
$top = $match;
}
else {
$bot = $match;
}
}
}
die "usage: $0" .
"\n\nMust have data on pasteboard to use this.\n\n" .
"Pasteboard should include at least two git hashes.\n\n" .
"Diff will be done of two most distant hashes.\n\n"
unless (defined($top) && defined($bot));
print "diff of $bot and $top:\n\n";
print `git diff $bot $top`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment