Last active
February 28, 2024 23:16
-
-
Save nibble-4bits/086f60618a498593616c0e940d52b0d7 to your computer and use it in GitHub Desktop.
A perl script that displays the git log and highlights the commits returned by `git cherry`, hence why its called git-v(isual)cherry :)
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Term::ANSIColor; | |
my $latest_commit = `git log --oneline -n 1`; | |
my ($commit_hash) = $latest_commit =~ /^([0-9a-f]+)/; | |
my $commit_length = length $commit_hash; | |
my $cherry_commits = `git cherry @ARGV`; | |
my @needed = $cherry_commits =~ /^\+ (\w+)/gm; | |
my @not_needed = $cherry_commits =~ /^\- (\w+)/gm; | |
@needed = map ( substr( $_, 0, $commit_length ), @needed ); | |
@not_needed = map ( substr( $_, 0, $commit_length ), @not_needed ); | |
my %needed_set; | |
@needed_set{@needed} = (); | |
my %not_needed_set; | |
@not_needed_set{@not_needed} = (); | |
my $git_log = `git log --all --decorate --oneline --graph --color=always`; | |
for my $line ( split( /\n/, $git_log ) ) { | |
if ( $line =~ /([0-9a-f]{$commit_length})/ ) { | |
if ( exists $needed_set{$1} ) { | |
substr( $line, $-[0], $commit_length, colored( $1, "on_ansi22" ) ); | |
} | |
elsif ( exists $not_needed_set{$1} ) { | |
substr( $line, $-[0], $commit_length, colored( $1, "on_ansi52" ) ); | |
} | |
} | |
print "$line\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use, add alias to
.gitconfig
like this: