git-find-blob (faster)

Michael Stone, March 17, 2012, , (src), (all posts)

Presently, Google’s index seems to know three different answers to the question: “how do I find the (git) commit that introduced blob X?”; however, all three answers solve the problem with O(N) processes, which is slow. A better solution, using only O(1) processes (and O(1) memory?) looks like this:

HASH=$(git hash-object -t blob /path/to/blob/to/find.c)
git log --pretty=oneline --diff-filter=A --raw --abbrev=40 \
  | grep -e '^[^:]' -e $HASH \
  | grep -B 1 '^:'

Can you do better?