CodeBlanks Logo Icon CodeBlanks

Internals

Inspect the object database and verify the packfile structure.

Git Object Database and Packfiles

Git objects (blob, tree, commit, tag) are stored under .git/objects by their SHA-1 hashes. Initially stored as loose objects, they are compressed into packfiles consisting of .pack and .idx files when git gc or git repack runs. The git verify-pack command verifies packfile integrity and its contained objects.

git verify-pack -v .git/objects/pack/*.idx
git cat-file -t <hash>

Practice Inspect Object Type

Add hello.txt to the object database using git hash-object -w. Then inspect the object SHA hash with git cat-file -t to print its type to the terminal.

Starter code

terminal
git init -q
echo "CodeBlanks" > hello.txt

# hash-object ile veritabanına yaz ve türü cat-file ile yazdır

Sample solution

terminal
git init -q
echo "CodeBlanks" > hello.txt
HASH=$(git hash-object -w hello.txt)
git cat-file -t $HASH

Expected output

blob

Practice Pack Objects and Verify

Run git repack -a -d -q in the repository to pack all loose objects. Then verify the packfile with git verify-pack and print PACK OK to the terminal upon success.

Starter code

terminal
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "v1" > app.txt
git add app.txt
git commit -m "feat" -q

# repack ile paketle ve verify-pack sonrasında PACK OK yazdır

Sample solution

terminal
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "v1" > app.txt
git add app.txt
git commit -m "feat" -q
git repack -a -d -q
git verify-pack .git/objects/pack/*.idx >/dev/null && echo "PACK OK"

Expected output

PACK OK

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the primary purpose of packfile (.pack) files in a repository?

  • To automatically distribute the repository to a remote server
  • To compress loose objects saving disk space and network bandwidth Correct answer
  • To encrypt commit messages preventing unauthorized reading
  • To back up reflog entries for recovering deleted branches

Explanation: Git bundles loose objects with delta compression instead of storing them individually, drastically reducing disk space and transfer time.

2 Verify Packfile

Question
git verify-pack ____-v .git/objects/pack/pack-demo.idx
Answer
git verify-pack v-v .git/objects/pack/pack-demo.idx

Explanation: The -v (verbose) flag lists the SHA hash, type, and size of every object inside the pack file.

3 Git Internals

Term Meaning
blob Stores file content
tree Stores directory structure
packfile Compressed object pack
.idx Pack object index

All lessons in Expert