Git Deep Dive Test
A watchmaker can tell a good watch from a bad one by listening to it tick, because they know every gear inside. This test asks whether you know Git that well: how objects are named and stored, what makes a commit reachable, how Git finds a merge base, when garbage collection really deletes something, and what is changing underneath with SHA-256 and reftable. It is for the Deep Dive track and for senior interviews.
How the Test Works
- What's in it: 20 multiple-choice questions, then 3 puzzles where you work out what Git prints at the end of a short terminal session.
- Time: 30 minutes, without notes and without running Git.
- Pass mark: 16 out of 23. The quiz marks the 20 questions for you; give yourself one point for each puzzle you get exactly right.
- What it covers: the Level 4 lessons on how Git works inside, starting with Git Internals.
Part 1: 20 Questions
Part 2: "What Does Git Print?" Puzzles
Work out what the last command of each session prints, on paper, before you open the solution. Each session starts in a new, empty temporary folder, with your name and email address set and main as the default branch.
Puzzle 1: Counting Objects
cd "$(mktemp -d)"
git init --quiet
mkdir docs
echo 'Term fee: $12,000' > fees.txt
echo 'Term fee: $12,000' > docs/fees-copy.txt
git add .
git commit --quiet -m "Add the fees and a copy"
git count-objects -v | grep "^count"Show solution
cd "$(mktemp -d)"
git init --quiet
mkdir docs
echo 'Term fee: $12,000' > fees.txt
echo 'Term fee: $12,000' > docs/fees-copy.txt
git add .
git commit --quiet -m "Add the fees and a copy"
git count-objects -v | grep "^count"count: 4Why this output?
Four loose objects: one blob (both files have identical content, so they share it), two trees (the top folder and docs) and one commit. File names are stored in the trees, which is why the copy costs no extra blob. Revise: Git Objects: Blob, Tree, Commit and Tag.
Puzzle 2: What Becomes Unreachable
cd "$(mktemp -d)"
git init --quiet
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
echo 'Late fee: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
git reset --quiet --hard HEAD~1
git fsck --unreachable --no-reflogs 2>/dev/null | cut -d " " -f 2 | sortShow solution
cd "$(mktemp -d)"
git init --quiet
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
echo 'Late fee: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
git reset --quiet --hard HEAD~1
git fsck --unreachable --no-reflogs 2>/dev/null | cut -d " " -f 2 | sortblob
commit
treeWhy this output?
--no-reflogs ignores the reflog, so the reset commit counts as unreachable, together with the tree and blob that only it uses. The first commit, its tree and its blob are still reachable from main. With the reflog counted (the default), nothing would be listed, which is why git gc keeps such commits for weeks. Revise: Git Recovery: Getting Lost Work Back.
Puzzle 3: A SHA-256 Commit ID
cd "$(mktemp -d)"
git init --quiet --object-format=sha256
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
git rev-parse HEAD | awk '{ print length($0) }'
git log --format=%h | awk '{ print length($0) }'Show solution
cd "$(mktemp -d)"
git init --quiet --object-format=sha256
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
git rev-parse HEAD | awk '{ print length($0) }'
git log --format=%h | awk '{ print length($0) }'64
7Why this output?
A full SHA-256 ID has 64 hex digits, but the short form is still 7 digits in a small repository: Git abbreviates to the shortest unique prefix, with a minimum of 7. That is why git log --oneline looks the same in both formats. (Both lines are printed by this puzzle's last two commands.) Revise: Git 3.0: What Is Planned.
What Your Score Means
| Score (out of 23) | What it means | What to do next |
|---|---|---|
| 20 to 23 | You know Git inside out | Answer the Hard questions on 50 Git Interview Questions and Answers out loud, and try building a commit by hand |
| 16 to 19 | Strong, with a few gaps | Read the lessons linked from the questions you missed |
| Under 16 | Not yet | Work through the Level 4 lessons, starting with Git Internals, then take the test again |
Was this tutorial helpful?