如何获取Git存储库中所有Blob的列表 [英] How to get a list of all blobs in a repository in Git

查看:325
本文介绍了如何获取Git存储库中所有Blob的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何列出git存储库中所有文件的所有版本?

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 used to cat the file.

推荐答案

这是如何获取存储库中所有blob的SHA和文件名的列表:

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-

注意:

  1. 格式字符串中的%(rest)原子将对象的SHA之后的其余输入行追加到输出中.在这种情况下,其余的碰巧是路径名(对于树和blob对象).

  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).

grep模式旨在仅匹配实际的blob,而不匹配仅在其路径名中某处具有字符串blob的树对象.

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.

这篇关于如何获取Git存储库中所有Blob的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆