benmmurphy benmmurphy - 1 year ago 99
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 Source

The following scriptlet should do the trick:



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