Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add closest match finding script

it finds the closest match from all (or a limited amount) of the reachable trees to a specified tree (where tree is referenced by it's checksum)
very useful to process the results of `git fsck --unreachable | cut -d\  -f3`
  • Loading branch information...
commit e90671c67f1e3334f71dcab17eeb63f4a51adf7a 1 parent 20b629d
@Dieterbe authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 git-closest-match
View
25 git-closest-match
@@ -0,0 +1,25 @@
+#!/bin/sh
+# find the closest match from all (or a limited amount) of the reachable trees to a specified tree (where tree is referenced by it's checksum)
+# very useful to process the results of `git fsck --unreachable | cut -d\ -f3`
+
+spec=$1
+mode=${2:-diff} # num: number of lines or diff: actual diff/log message?
+range=${3:-30} # 'all' or most recent <num> in current branch?. 'all' can be quite slow
+if [ "$range" = 'all' ]; then
+ all=`git-rev-list --all | awk '/^commit/ {print $NF}'`
+else
+ all=`git log -n $range | awk '/^commit/ {print $NF}'`
+fi
+
+commit=`for i in $all; do
+ echo -n "$i "
+ # why is there no git diff --shortnumstat ?
+ git diff -M $spec $i | wc -l
+done | sort -k 2 -n | head -n 1 | cut -f 1 -d ' '`
+if [ "$mode" = diff ]; then
+ git log --no-walk $commit | cat -
+ git diff -M $spec $commit | cat -
+else
+ echo -n "$commit: "
+ git diff -M $spec $commit | wc -l
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.