Git Deep Dive Test

Updated · 10 min read
hardGit 2.53gittestquizinternalsdeep-diveassessment

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

Deep Dive test: 20 questions

20 questions
1Why can't someone change an old commit's message without changing every later commit's ID?
2What does a tree object store for each entry?
3What is the difference between an annotated tag and a lightweight tag internally?
4Besides the mode and blob ID, what does the index store for each file that makes git status fast?
5What is a symbolic ref?
6Inside a packfile, what is a delta?
7When does git gc delete an unreachable commit by default?
8What does git fsck --lost-found do?
9How does git merge choose the base for a three-way merge?
10In a criss-cross history with two equally good merge bases, what does ort do?
11What does git merge-tree --write-tree a b change in your repository?
12What does git log --remerge-diff show for a merge commit?
13What is a generation number in the commit-graph?
14What is a promisor remote?
15Which bit in the index marks a file that sparse checkout leaves out of the working tree?
16Where is a commit's signature stored?
17How does Git protect against the 2017 SHA-1 collision attack?
18How long is a full object ID in a SHA-256 repository?
19Where does a reftable repository keep its references?
20What records a repository's object format, so that old Git versions refuse a SHA-256 repository?

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

Terminal
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
Terminal
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"
Output
count: 4
Why 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

Terminal
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 | sort
Show solution
Terminal
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 | sort
Output
blob
commit
tree
Why 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

Terminal
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
Terminal
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) }'
Output
64
7
Why 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 meansWhat to do next
20 to 23You know Git inside outAnswer the Hard questions on 50 Git Interview Questions and Answers out loud, and try building a commit by hand
16 to 19Strong, with a few gapsRead the lessons linked from the questions you missed
Under 16Not yetWork through the Level 4 lessons, starting with Git Internals, then take the test again

Was this tutorial helpful?