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?
Asked
Active
Viewed 1,855 times
2 Answers
11
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

jacknagel
- 1,301
- 1
- 10
- 8
1
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)

Philip Oakley
- 13,333
- 9
- 48
- 71