Skip to content

Instantly share code, notes, and snippets.

@paudirac
Created July 10, 2019 16:20
Show Gist options
  • Save paudirac/078e4918b0e5bc0a42e3cebbbd504ccc to your computer and use it in GitHub Desktop.
Save paudirac/078e4918b0e5bc0a42e3cebbbd504ccc to your computer and use it in GitHub Desktop.
Inspect git objects of a folder
#!/bin/bash
list_objects () {
find .git/objects/ -type f | sed s:.git/objects/:: | sed s:/::
}
list_types () {
list_objects | xargs -n1 git cat-file -t
}
count_type () {
echo $1: $(list_types | grep $1 | wc -l)
}
show_detail () {
while read obj; do
echo -e $(git cat-file -t $obj) "\t$obj"
done
}
list_details () {
list_objects | show_detail
}
cd $1
echo "Git objects of $1"
echo $(count_type blob) $(count_type tree) $(count_type commit)
echo ----------------------------------------------------------
list_details
@paudirac
Copy link
Author

This is mainly for demo purposes in tiny repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment