
This third Git set opens the hood. First we look at how Git stores your data as objects and refs. Then we move to the tools senior developers use often: bisect, blame, worktrees, submodules, hooks and sparse checkout. Each explanation links the command back to what Git really stores on disk.
How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 15 questions.
Topics covered in this set
- Blob, tree, commit and tag objects
- SHA hashes, refs and packfiles
- Detached HEAD, git bisect and git blame
- Worktrees, submodules and subtrees
- pre-commit, commit-msg and pre-push hooks
- .gitattributes and sparse checkout
Git MCQs with answers and explanations
Q1. Git stores four kinds of objects: blob, tree, commit and annotated tag. Which object records file names and their permissions?
a) Blob
b) Commit
c) Tree
d) Annotated tag
Q2. You change only the message of a commit five commits back using interactive rebase. Why do the hashes of all five later commits change too?
a) Commit hashes are random and regenerated on each rebase
b) The commit date of every commit is reset to today
c) Each commit stores the hash of its parent, so a new hash for one commit changes the content, and therefore the hash, of every descendant
d) Git re-compresses every commit during a rebase
Q3. In a repository using SHA-1, what does the file .git/refs/heads/main normally contain?
a) A list of every commit on main
b) The text ref: refs/heads/main
c) The 40-character hexadecimal hash of the commit that main points to
d) A copy of the latest snapshot of all files
Q4. What does running git gc do to loose objects in .git/objects?
a) Converts them to plain text files
b) Deletes every object not on the current branch immediately
c) Packs them into packfiles, storing similar objects as deltas against each other to save space, with an .idx index for fast lookup
d) Uploads them to the remote
Q5. You run git checkout v2.0 (a tag), make one commit, then run git switch main. What happens to the new commit?
a) It is added to the v2.0 tag
b) It belongs to no branch; Git warns about it, and it can be found through the reflog until it is garbage collected
c) It is merged into main automatically
d) It is deleted immediately
Q6. A bug appeared somewhere in the last 1,000 commits. Roughly how many builds must you test with git bisect to find the first bad commit?
a) About 100
b) About 500
c) About 10
d) About 1,000
Q7. A team ran a code formatter over the whole repository in one commit, and now git blame shows that commit on almost every line. What is the cleanest fix?
a) Run git blame with --reverse
b) Delete the commit with git reset
c) Revert the formatting commit
d) List the formatting commit's hash in a file such as .git-blame-ignore-revs and pass it with --ignore-revs-file (or set blame.ignoreRevsFile)
Q8. You are mid-way through a feature with uncommitted changes and need to fix an urgent bug on main without stashing. Which command helps?
a) git clone --mirror
b) git worktree add ../hotfix -b hotfix main, which creates a second working directory on a new branch that shares the same repository
c) git stash --keep-index
d) git switch --discard-changes main
Q9. What does a parent repository actually store for a Git submodule at lib/?
a) Only the submodule's latest tag
b) A symbolic link to the remote URL
c) A full copy of the submodule's files in its own history
d) A special entry (a gitlink, mode 160000) pointing to one exact commit of the submodule, plus its URL in .gitmodules
Q10. How does git subtree differ from a submodule for including a shared library?
a) Subtree copies the library's files into the main repository's history, so a normal clone gets everything with no extra commands
b) Subtree requires every developer to install a server
c) Subtree keeps the library in a separate repository that users must clone separately
d) Subtree works only for binary files
Q11. A script at .git/hooks/pre-commit runs a linter and exits with status 1. What happens when you run git commit?
a) The commit is pushed without the lint changes
b) The commit is aborted; git commit --no-verify would skip the hook
c) The hook is ignored because it is not executable by default
d) The commit is created and a warning is shown
Q12. Which hook is the right place to reject commits whose message does not follow a format such as feat: add login?
a) pre-push
b) post-commit
c) post-checkout
d) commit-msg, which receives the path to the message file as its first argument
Q13. A team wants the full test suite to run before code leaves a developer's machine, but not on every single commit. Which hook fits?
a) pre-push
b) post-merge
c) prepare-commit-msg
d) pre-commit
Q14. Shell scripts committed from Windows machines fail on Linux with "bad interpreter" errors caused by CRLF line endings. Which .gitattributes line fixes this for future checkouts?
a) *.sh merge=union
b) *.sh binary
c) *.sh -diff
d) *.sh text eol=lf
Q15. In a large monorepo you only need the apps/web folder in your working tree. Which command does this?
a) git rm -r --cached .
b) git sparse-checkout set apps/web
c) git worktree add apps/web
d) git archive apps/web
Quick revision notes
- Blob = content, tree = directory listing, commit = tree + parents + metadata, annotated tag = named pointer with message.
- Hashes cover content including the parent hash, so editing old commits changes all later hashes.
- A branch is a file holding a hash. git gc packs loose objects into delta-compressed packfiles.
- bisect needs about log₂(N) tests; ignore formatting commits in blame with .git-blame-ignore-revs.
- Hooks: pre-commit for lint, commit-msg for message format, pre-push for tests. --no-verify skips them.
Frequently asked questions
How do I share Git hooks with my whole team?
Hooks inside .git/hooks do not get cloned. Commit them to a folder like .githooks and set core.hooksPath, or use a tool like Husky or pre-commit that installs them for each developer.
Should I use submodules or a package manager for shared code?
If you can publish the code as a versioned package, a package manager is usually easier. Use submodules when you need the actual source locked to one exact commit.
Is Git moving away from SHA-1?
Git already supports SHA-256 repositories (git init --object-format=sha256), but SHA-1 is still the default in Git 2.x. The SHA-1 that Git uses is a hardened version that catches known collision attacks. Git 3.0 plans to make SHA-256 the default for new repositories, so check the release notes of your version.
Comments
Post a Comment