Git Level 3 Test

Updated · 10 min read
mediumGit 2.53gittestquizrebaseassessment

A cook who can follow a recipe is useful. A cook who can rescue a dish that went wrong, and explain what went wrong, runs the kitchen. This test checks the rescue skills of Git: rewriting and cleaning up history, moving commits between branches, recovering lost work, hunting down the commit that broke something, and working in a team's workflow. If you pass it, you are ready for the advanced level.

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 lessons from "Git Rebase" to "Code Review and Pull Request Etiquette".

Part 1: 20 Questions

Level 3 test: 20 questions

20 questions
1What does git rebase main do when run on feature/books?
2What is the "golden rule" of rebasing?
3During a rebase, a commit conflicts. After fixing the file and running git add, what do you run?
4What does git rebase --onto main feature/base feature/top do?
5What does git commit --amend --no-edit do?
6In an interactive rebase to-do list, what is the difference between squash and fixup?
7What does git commit --fixup=<commit> create?
8A password was committed three commits ago and deleted in the next one. Is it gone from the repository?
9What does git cherry-pick -x <commit> add to the new commit's message?
10Which git reset mode keeps the undone changes in your files but not staged?
11You made two commits on main that belong on a new branch. Nothing is pushed. What is the usual fix?
12What does the reflog record?
13A dropped stash is no longer in the reflog. Which command can still find it?
14In git bisect run <command>, what does an exit code of 0 mean?
15Which git blame option ignores whitespace-only changes?
16What is the difference between git log -S "lateFee" and git log -G "lateFee"?
17Which workflow keeps long-lived main and develop branches plus release and hotfix branches?
18Which practice helps most to keep main always working?
19What does git range-diff help a reviewer see?
20What does "squash and merge" do to a pull request's commits?

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: A Straight Line After Rebase

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"
git switch --quiet -c feature/books
echo 'Books fee: $600' > books.txt
git add books.txt
git commit --quiet -m "Add the books fee"
git switch --quiet main
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
git switch --quiet feature/books
git rebase --quiet main
git log --graph --format=%s
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"
git switch --quiet -c feature/books
echo 'Books fee: $600' > books.txt
git add books.txt
git commit --quiet -m "Add the books fee"
git switch --quiet main
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
git switch --quiet feature/books
git rebase --quiet main
git log --graph --format=%s
Output
* Add the books fee
* Add the exam fee
* Add the term fee
Why this output?

The rebase replayed "Add the books fee" on top of main's newest commit, so the branch history is one straight line, with no merge commit. Compare this with the merge puzzle in the Level 2 test, which made the same changes with a fork and a merge. Revise: Git Rebase.

Puzzle 2: Autosquash

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: $25' >> fees.txt
git commit --quiet -am "Add the late fee"
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
sed -i.bak 's/\$25$/$250/' fees.txt && rm fees.txt.bak
git commit --quiet -a --fixup=HEAD~1
GIT_SEQUENCE_EDITOR=true git rebase --quiet -i --autosquash HEAD~3
git log --format=%s
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: $25' >> fees.txt
git commit --quiet -am "Add the late fee"
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
sed -i.bak 's/\$25$/$250/' fees.txt && rm fees.txt.bak
git commit --quiet -a --fixup=HEAD~1
GIT_SEQUENCE_EDITOR=true git rebase --quiet -i --autosquash HEAD~3
git log --format=%s
Output
Add the exam fee
Add the late fee
Add the term fee
Why this output?

--fixup=HEAD~1 created a commit named "fixup! Add the late fee". --autosquash moved it right after "Add the late fee" in the to-do list and marked it fixup, and GIT_SEQUENCE_EDITOR=true accepted the list without opening an editor. The fix was folded in, so the fixup commit disappeared and the late fee commit now contains $250. Revise: Fixup Commits and Autosquash.

Puzzle 3: What the Reflog Remembers

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 reflog --format=%gs
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 reflog --format=%gs
Output
reset: moving to HEAD~1
commit: Add the late fee
commit (initial): Add the term fee
Why this output?

%gs prints each reflog entry's description, newest first: the reset, the commit it undid, and the first commit. The "lost" commit is still listed, so git reset --hard HEAD@{1} would bring it back. Revise: Git Reflog.

What Your Score Means

Score (out of 23)What it meansWhat to do next
20 to 23You can clean up and rescue any historyMove on to Git Internals Overview
16 to 19A pass, with a few gapsRead the lessons linked from the questions you missed, then move on
Under 16Not yetReread the lessons behind your wrong answers, do Lab 3 and Lab 7 on Git Labs, and take the test again

Was this tutorial helpful?