How to get a list of all blobs in a repository in Git

后端 未结 3 908
無奈伤痛
無奈伤痛 2021-01-18 17:51

How can I list all versions of all files in a git repository?

(For example for listing all files that ever contained a certain string)

This list could be use

3条回答
  •  野的像风
    2021-01-18 18:44

    This is how I get a list of SHAs and filenames for all the blobs in a repository:

    $ git rev-list --objects --all | git cat-file --batch-check='%(objectname) %(objecttype) %(rest)' | grep '^[^ ]* blob' | cut -d" " -f1,3-
    

    Notes:

    1. The %(rest) atom in the format string appends the rest of the input line after the object's SHA to the output. In this case, this rest happens to be the path name (for tree and blob objects).

    2. The grep pattern is intended to match only actual blobs, not tree objects which just happen to have the string blob somewhere in their path name.

提交回复
热议问题