diff --git a/git_helpers b/git_helpers index e52ace9..1dbf1b7 100755 --- a/git_helpers +++ b/git_helpers @@ -224,4 +224,20 @@ changed_file_names () { "while in $PWD" fi } -# fi + +get_blob () { # get the blob of the file(name) passed as $1 + # note: this can be used for any file in the filesystem + echo $(git hash-object $1) +} + +get_commit_for_blob () { + blob=$(get_blob $1) + if [ ! -z $blob ]; then + # search for the blob in all commits for the file(name) $1 + echo $(echo $(git log --all --pretty=format:%H -- $1) | + xargs -I{} sh -c "git ls-tree {} -- $1 | + grep -q $blob && echo {}") + fi +} + +