Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git List Commits By Blobs

Tags:

git

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?

like image 401
benmmurphy Avatar asked May 22 '12 20:05

benmmurphy


2 Answers

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
like image 137
jacknagel Avatar answered Oct 06 '22 00:10

jacknagel


Maybe a bit late, but git show <abbrev-sha1> will show the contents of that blob etc. As will git cat-file blob <abbrev-sha1>, use git cat-file -t <abbrev-sha1> to check it's a blob.

Getting the first (or last) commit that contained it appears not as easy (such as determining from a patch's diff index line, where that patch came from)

like image 31
Philip Oakley Avatar answered Oct 06 '22 00:10

Philip Oakley