5

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?

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.