【问题标题】:Git List Commits By BlobsGit 按 Blob 列出提交
【发布时间】:2012-05-22 20:58:25
【问题描述】:

假设我有一个 blob 的 SHA。我可以去 git show 看看 blob 的内容。是否可以获得包含该 blob 的所有提交的列表?

【问题讨论】:

    标签: git


    【解决方案1】:

    下面的 scriptlet 应该可以解决问题:

    #!/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
    

    【讨论】:

      【解决方案2】:

      可能有点晚了,但git show <abbrev-sha1> 将显示该 blob 的内容等。git cat-file blob <abbrev-sha1> 也一样,使用 git cat-file -t <abbrev-sha1> 来检查它是一个 blob。

      获取包含它的第一个(或最后一个)提交似乎并不容易(例如从补丁的差异index 行确定该补丁的来源)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-11
        • 2017-12-19
        • 2018-09-20
        • 2020-08-23
        • 2012-08-23
        • 1970-01-01
        • 1970-01-01
        • 2014-10-04
        相关资源
        最近更新 更多