如何列出数据库中的所有git对象? [英] How to list ALL git objects in the database?
问题描述
是否有比以下方式更好的方法来获取存储库中所有对象的SHA1原始列表: ls .git/objects/??/\ *
和 cat .git/objects/pack/*.idx |git show-index
Is there a better way of getting a raw list of SHA1s for ALL objects in a repository than:
ls .git/objects/??/\*
and
cat .git/objects/pack/*.idx | git show-index
我了解 git rev-list --all
,但是仅列出了 .git/refs
引用的提交对象,而我正在寻找所有,包括由 git-hash-object
, git-mktree
等创建的未引用对象.
I know about git rev-list --all
but that only lists commit objects that are referenced by .git/refs
, and I'm looking for everything, including unreferenced objects that are created by git-hash-object
, git-mktree
etc.
推荐答案
亚里斯多德发布了
Aristotle posted an even better answer, which should be marked as correct.
编辑:该脚本包含语法错误,在 grep -v
行的末尾缺少反斜杠
the script contained a syntax error, missing backslash at the end of the grep -v
line
经过一些修改,马克的答案对我有用:
Mark's answer worked for me, after a few modifications:
- 使用
-git-dir
而不是-show-cdup
来支持裸仓库 - 没有包装时避免错误
- 使用
perl
是因为OS X Mountain Lion的BSD样式的sed
不支持-r
- Used
--git-dir
instead of--show-cdup
to support bare repos - Avoided error when there are no packs
- Used
perl
because OS X Mountain Lion's BSD-stylesed
doesn't support-r
#!/bin/sh
set -e
cd "$(git rev-parse --git-dir)"
# Find all the objects that are in packs:
find objects/pack -name 'pack-*.idx' | while read p ; do
git show-index < $p | cut -f 2 -d ' '
done
# And now find all loose objects:
find objects/ \
| egrep '[0-9a-f]{38}' \
| grep -v /pack/ \
| perl -pe 's:^.*([0-9a-f][0-9a-f])/([0-9a-f]{38}):\1\2:' \
;
这篇关于如何列出数据库中的所有git对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!