Bird
Raised Fist0
Gitdevops~20 mins

Git mental model (snapshots not diffs) - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Git Snapshot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does Git store changes internally?

Git is often described as storing snapshots rather than diffs. What does this mean?

AGit stores file changes as patches that must be applied manually.
BGit saves only the differences between files for each commit.
CGit stores only the latest file versions and discards history.
DGit saves the entire state of all files at each commit as a snapshot.
Attempts:
2 left
💡 Hint

Think about how Git can quickly restore any commit without applying patches.

💻 Command Output
intermediate
2:00remaining
What does 'git cat-file -p HEAD' show?

Run git cat-file -p HEAD in a repository. What output do you expect?

AThe diff between the last two commits.
BThe full snapshot of the latest commit's tree and metadata.
CThe list of all branches in the repository.
DThe current status of uncommitted changes.
Attempts:
2 left
💡 Hint

HEAD points to the latest commit object.

🔀 Workflow
advanced
2:30remaining
How does Git optimize storage of snapshots?

Git stores snapshots for each commit. How does it avoid storing duplicate file data repeatedly?

AGit stores identical files only once using object hashing and references.
BGit compresses all files into a single archive per commit.
CGit stores full copies of all files for every commit without optimization.
DGit deletes unchanged files from previous commits to save space.
Attempts:
2 left
💡 Hint

Think about how Git uses SHA-1 or SHA-256 hashes for objects.

Troubleshoot
advanced
2:00remaining
Why does 'git diff' show no output after a commit?

You just committed changes, but running git diff shows no output. Why?

ABecause the commit was empty and did not change any files.
BBecause Git lost track of the commit history.
CBecause the working directory matches the latest commit snapshot exactly.
DBecause the repository is corrupted and cannot show diffs.
Attempts:
2 left
💡 Hint

Think about what git diff compares by default.

Best Practice
expert
3:00remaining
Why prefer snapshots over diffs in Git's design?

Git uses snapshots instead of diffs internally. What is a key advantage of this design?

AIt allows fast checkout and recovery by restoring complete file states directly.
BIt reduces repository size more than storing diffs would.
CIt makes merging changes impossible, simplifying history.
DIt requires less CPU power to compute diffs on demand.
Attempts:
2 left
💡 Hint

Think about how Git restores files when switching commits.

Practice

(1/5)
1. What does Git save when you run git commit?
easy
A. A backup copy of your entire computer
B. Only the changes made since the last commit
C. A list of all commands you typed
D. A snapshot of all your files at that moment

Solution

  1. Step 1: Understand what git commit does

    It records the current state of your project files as a snapshot.
  2. Step 2: Differentiate snapshot from changes

    Unlike some systems, Git saves the whole snapshot, not just the changes.
  3. Final Answer:

    A snapshot of all your files at that moment -> Option D
  4. Quick Check:

    Git saves snapshots, not diffs [OK]
Hint: Remember: Git snapshots whole files, not just changes [OK]
Common Mistakes:
  • Thinking Git saves only changes (diffs)
  • Confusing commit with backup
  • Believing commit saves command history
2. Which of the following is the correct command to create a snapshot in Git?
easy
A. git snapshot
B. git save
C. git commit
D. git backup

Solution

  1. Step 1: Recall Git commands for saving work

    The command to save a snapshot is git commit.
  2. Step 2: Verify other options

    Commands like git snapshot, git save, and git backup do not exist in Git.
  3. Final Answer:

    git commit -> Option C
  4. Quick Check:

    git commit creates snapshots [OK]
Hint: Use git commit to save snapshots [OK]
Common Mistakes:
  • Using non-existent commands like git save
  • Confusing commit with backup commands
  • Trying git snapshot which is invalid
3. Given this sequence of commands:
echo "Hello" > file.txt
git add file.txt
git commit -m "First snapshot"
echo "World" >> file.txt
git add file.txt
git commit -m "Second snapshot"

What does the second commit snapshot contain?
medium
A. Only the line "World" added to file.txt
B. The entire file.txt with both "Hello" and "World" lines
C. Only the line "Hello" in file.txt
D. An empty file.txt

Solution

  1. Step 1: Understand what each commit saves

    Each commit saves a full snapshot of the file at that time, not just changes.
  2. Step 2: Analyze the second commit content

    After appending "World", the second commit snapshot includes both "Hello" and "World" lines in file.txt.
  3. Final Answer:

    The entire file.txt with both "Hello" and "World" lines -> Option B
  4. Quick Check:

    Git snapshots save full file content [OK]
Hint: Each commit saves full file content, not just added lines [OK]
Common Mistakes:
  • Thinking commit saves only new lines
  • Confusing snapshots with diffs
  • Assuming commit saves partial file
4. You ran git commit but Git says "nothing to commit, working tree clean". What is the most likely reason?
medium
A. There are no changes since the last snapshot
B. You forgot to add files with git add before commit
C. Your Git repository is corrupted
D. You need to restart your computer

Solution

  1. Step 1: Understand the message meaning

    "Nothing to commit, working tree clean" means no changes are detected compared to last commit.
  2. Step 2: Check if files were changed

    If no files changed, Git has no new snapshot to save, so commit does nothing.
  3. Final Answer:

    There are no changes since the last snapshot -> Option A
  4. Quick Check:

    No changes = no new snapshot [OK]
Hint: No changes means no new commit possible [OK]
Common Mistakes:
  • Assuming you must always run git add before commit even if no changes
  • Thinking repository is corrupted
  • Restarting computer unnecessarily
5. You want to save your project state but only some files changed. How does Git store this when you run git commit?
hard
A. Git saves a full snapshot of all files, but reuses unchanged files from previous commits internally
B. Git saves only the changed files as diffs
C. Git saves only the changed files as full copies
D. Git saves nothing until you run git push

Solution

  1. Step 1: Recall Git snapshot model

    Git saves a full snapshot of the project at commit time, not just diffs.
  2. Step 2: Understand Git's storage optimization

    Internally, Git reuses unchanged files from previous commits to save space efficiently.
  3. Final Answer:

    Git saves a full snapshot of all files, but reuses unchanged files from previous commits internally -> Option A
  4. Quick Check:

    Snapshots with internal reuse = Git saves a full snapshot of all files, but reuses unchanged files from previous commits internally [OK]
Hint: Git snapshots all files but stores unchanged ones efficiently [OK]
Common Mistakes:
  • Thinking Git saves only diffs
  • Believing commit saves nothing until push
  • Assuming changed files are saved as full copies only