benmmurphy benmmurphy - 2 months ago 18
Git Question

Git List Commits By Blobs

Say I have the SHA for a blob. I can go git show and see the contents of the blob. Is it possible to get a list of all the commits that contain that blob?

Answer

The following scriptlet should do the trick:

#!/bin/sh

blob=deadbeefdeadbeefdeadbeefdeadbeef

git rev-list --all |
while read commit; do
    if git ls-tree -r $commit | grep -q $blob; then
        echo $commit
    fi
done
Comments