From db1918af4eaf37c1a1cf88b7fffeed5aa23a2b5a Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Wed, 22 Feb 2023 23:41:42 -0600 Subject: [PATCH] Added Git history comparator (#walker) Hashwalker is a new tool that allows you to compare two branches or refspecs with completely different histories to find the commit where they differ the least. To use it you will need to add your disparate repositories as remotes on a single repository on your local machine. You'll need to have two checked out branches to compare, as well. One branch is your target you'd like to rebase and the other is an upstream you'd like to rebase upon. Running the tool will give you a minimal diff that you can rebase your problem branch upon, so you can begin bringing it up-to-date with upstream. See the "Usage" in scripts/hashwalker for more information. --- scripts/hashwalker | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/hashwalker diff --git a/scripts/hashwalker b/scripts/hashwalker new file mode 100755 index 0000000..da14a89 --- /dev/null +++ b/scripts/hashwalker @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +. $(dirname $0)/util/logging.bash + +: ' + * Have a derivative project loosely based around another (à la copy-paste) + * that you would like to graft back onto the tree where it came from?? + * Try hashwalker!! + ' + +read -d '' usage </dev/null) ) + +declare -a smallest +for (( i=${#hashes[@]} - 1 ; i>=0 ; i-- )); do + # Shrek was here. + changed=$(($(echo $(git diff ${hashes[i]} $branch_a --shortstat \ + | grep -o '[0-9]\+\s\+' | tail -n +2) \ + | sed 's/\s\+/+/g'))) + if [ ${#smallest[@]} -eq 0 ]; then + smallest=( ${hashes[i]} $changed ) + echo -n 'f' + else + [ $changed -lt ${smallest[1]} ] && smallest[0]=${hashes[i]} && smallest[1]=$changed \ + && echo -n '!' || echo -n '.' + fi +done +echo + +echo "Smallest diff @ ${smallest[0]}: $(git diff ${smallest[0]} $branch_a --shortstat)"