cat-file and hash-object

Inspecting Objects with cat-file and hash-object

git cat-file reads objects: -t prints the type, -s the size, -p pretty-prints and -e tests existence. git hash-object computes a name and, with -w, writes the object. The batch modes scan the whole database in one process:

Listing every object in the lab repositoryShell
git cat-file -t HEAD:README.md
git cat-file -s HEAD:README.md
git cat-file --batch-all-objects --batch-check
Output
blob
31
0be51cec615ba290d0cd9cd68508412c95aa6182 commit 236
25c8a459b6e162ac7b759d609872fcdbfce206f6 blob 9
2fdd7266111b3645450e0a6b49c48eb3d4882077 tree 66
64eb5254db7a4f751d2d72d53c4461fcc7fa1015 tree 66
653fc97f05515c8f22fe7b7865e1ae16351816d0 commit 187
6f046deb11577fe2bc71307bf78265c602bf8f86 blob 31
94568a7a08dacaf7a3afeb81ba74d6e3991cb40c blob 45
b5d16e349146c9e8137e044d0dd6045880b30de3 tree 38

Two commits took eight objects: three blobs, three trees and two commits. A custom format such as --batch-check='%(objectsize:disk) %(objectname)' finds the biggest objects on disk (Large Files and Big Repos), and git cat-file -p HEAD~3:package.json prints a file as it was three commits ago without checking anything out.