Skip to content

Instantly share code, notes, and snippets.

@nibble-4bits
Last active July 15, 2022 00:12
Show Gist options
  • Save nibble-4bits/1d34cf81d94a6dbe7c9305a1b38a7743 to your computer and use it in GitHub Desktop.
Save nibble-4bits/1d34cf81d94a6dbe7c9305a1b38a7743 to your computer and use it in GitHub Desktop.
A bash script that displays the git log and highlights the commits returned by `git cherry`, hence why its called git-v(isual)cherry :)
#!/bin/bash
set -eo pipefail
UPSTREAM=$1
HEAD=$2
HASHES=$(git cherry "$UPSTREAM" "$HEAD" | grep -F '+' | tr -d '+ ' | cut -c 1-7)
HASH_REGEX="/$(echo "$HASHES" | paste -sd '|' -)/"
AWK_PROG_TEMPLATE="$HASH_REGEX {
where = match(\$0, /[a-f0-9]{7,}/)
substring = substr(\$0, where, 7)
sub(substring, \"\033[1;7m&\")
}
{ print }
"
git log --all --decorate --oneline --graph --color=always | awk "$AWK_PROG_TEMPLATE" | less -R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment