Which commit has this blob?

前端 未结 7 2213
别那么骄傲
别那么骄傲 2020-11-22 02:45

Given the hash of a blob, is there a way to get a list of commits that have this blob in their tree?

7条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 03:29

    While the original question does not ask for it, I think it is useful to also check the staging area to see if a blob is referenced. I modified the original bash script to do this and found what was referencing a corrupt blob in my repository:

    #!/bin/sh
    obj_name="$1"
    shift
    git ls-files --stage \
    | if grep -q "$obj_name"; then
        echo Found in staging area. Run git ls-files --stage to see.
    fi
    
    git log "$@" --pretty=format:'%T %h %s' \
    | while read tree commit subject ; do
        if git ls-tree -r $tree | grep -q "$obj_name" ; then
            echo $commit "$subject"
        fi
    done
    

提交回复
热议问题