Bird
Raised Fist0
Gitdevops~20 mins

git fsck for repository integrity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Git Integrity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What does git fsck report when the repository is healthy?
Run git fsck on a perfectly intact Git repository. What output do you expect?
Git
git fsck
Aerror: missing blob object
Bfatal: not a git repository (or any of the parent directories): .git
Cerror: corrupt object detected
DChecking object directories: 100% (256/256), done.
Attempts:
2 left
💡 Hint
Think about what git fsck does when everything is fine.
🧠 Conceptual
intermediate
1:30remaining
What does git fsck check in a Git repository?
Select the best description of what git fsck verifies in a Git repository.
AIt verifies the integrity and connectivity of Git objects and references.
BIt merges branches and resolves conflicts automatically.
CIt cleans up unnecessary files and optimizes the repository.
DIt checks for uncommitted changes in the working directory.
Attempts:
2 left
💡 Hint
Think about what 'fsck' stands for in other systems.
❓ Troubleshoot
advanced
2:00remaining
You ran git fsck and got error: missing blob object. What is the likely cause?
After running git fsck, you see the error error: missing blob object. What does this mean?
AA Git object file is missing or corrupted, causing repository inconsistency.
BThe working directory is not clean; files are staged but not committed.
CThe repository has uncommitted changes that need to be committed.
DThe remote repository is unreachable due to network issues.
Attempts:
2 left
💡 Hint
Missing blob means Git cannot find an object it expects.
🔀 Workflow
advanced
2:30remaining
What is the correct sequence to verify and repair a corrupted Git repository?
You suspect your Git repository is corrupted. Which sequence of commands correctly checks and attempts to fix it?
A3,1,4,2
B1,3,4,2
C1,2,3,4
D2,1,3,4
Attempts:
2 left
💡 Hint
Start by checking integrity, then find good commits, reset, and clean up.
✅ Best Practice
expert
3:00remaining
Which practice helps prevent repository corruption detected by git fsck?
Choose the best practice that reduces the chance of repository corruption that git fsck would detect.
ADeleting the .git directory to reset the repository when errors occur.
BAvoiding commits and pushing directly to remote without local history.
CRegularly running <code>git gc</code> and backing up the .git directory.
DUsing shallow clones exclusively to reduce repository size.
Attempts:
2 left
💡 Hint
Think about maintenance and backups for safety.

Practice

(1/5)
1. What is the primary purpose of the git fsck command?
easy
A. To check the integrity and validity of objects in a Git repository
B. To clone a remote Git repository
C. To merge two branches automatically
D. To delete untracked files from the working directory

Solution

  1. Step 1: Understand the function of git fsck

    The git fsck command scans the Git repository to verify the integrity of objects like commits, trees, and blobs.
  2. Step 2: Compare with other Git commands

    Commands like clone, merge, and clean serve different purposes unrelated to repository integrity checks.
  3. Final Answer:

    To check the integrity and validity of objects in a Git repository -> Option A
  4. Quick Check:

    Repository integrity check = D [OK]
Hint: Remember: fsck means 'file system check' for Git data [OK]
Common Mistakes:
  • Confusing git fsck with git clone
  • Thinking it modifies files instead of checking
  • Assuming it deletes files or merges branches
2. Which of the following is the correct syntax to run a basic integrity check on your Git repository?
easy
A. git fsck --check
B. git check fsck
C. git fsck
D. git fsck --repair

Solution

  1. Step 1: Identify the correct command syntax

    The basic command to check repository integrity is simply git fsck without extra flags.
  2. Step 2: Understand invalid options

    Options like --check or --repair do not exist for git fsck, and git check fsck is not a valid Git command.
  3. Final Answer:

    git fsck -> Option C
  4. Quick Check:

    Basic integrity check command = B [OK]
Hint: Use just 'git fsck' to check integrity, no extra flags needed [OK]
Common Mistakes:
  • Adding non-existent flags like --check or --repair
  • Reversing command order like 'git check fsck'
  • Confusing with other Git commands
3. You run git fsck on your repository and see the output:
dangling commit 3a1b2c4d5e6f7g8h9i0j

What does this output mean?
medium
A. The commit is currently checked out in your working directory
B. The repository has corrupted files that must be deleted
C. The repository is fully healthy with no issues
D. There is a commit object not reachable from any branch or tag

Solution

  1. Step 1: Understand 'dangling commit' meaning

    A dangling commit is a commit object that exists in the repository but is not referenced by any branch, tag, or other refs.
  2. Step 2: Interpret the output context

    This does not mean corruption or errors; it means the commit is orphaned but still present.
  3. Final Answer:

    There is a commit object not reachable from any branch or tag -> Option D
  4. Quick Check:

    Dangling commit = orphaned but intact commit = A [OK]
Hint: Dangling means unreferenced, not broken [OK]
Common Mistakes:
  • Assuming dangling means corrupted
  • Thinking the commit is currently active
  • Ignoring the meaning of unreachable objects
4. You ran git fsck and got this error:
error: object file .git/objects/ab/cdef1234... is corrupt

What should you do to fix this problem?
medium
A. Restore the corrupted object from a backup or fetch from remote
B. Run git fsck --full to repair the corruption automatically
C. Delete the entire repository and clone it again
D. Ignore the error; it will not affect your repository

Solution

  1. Step 1: Understand the error meaning

    The error indicates a corrupted object file in the Git repository, which can cause problems.
  2. Step 2: Choose the correct fix approach

    Since git fsck only checks and does not repair, you should restore the corrupted object from a backup or fetch it from a remote repository.
  3. Final Answer:

    Restore the corrupted object from a backup or fetch from remote -> Option A
  4. Quick Check:

    Corruption fix = restore or fetch = C [OK]
Hint: Restore corrupted objects from backup or remote, fsck only checks [OK]
Common Mistakes:
  • Expecting git fsck to repair corruption automatically
  • Ignoring corruption errors
  • Deleting repo unnecessarily without backup
5. You want to ensure your Git repository is fully healthy before a big release. Which sequence of commands correctly uses git fsck and related steps to check and fix repository integrity?
hard
A. Run git fsck --repair to fix all errors automatically, then commit changes
B. Run git fsck, then if errors appear, restore corrupted objects from backup or remote, then run git fsck again
C. Run git fsck and delete all dangling commits to clean the repo
D. Run git fsck and ignore any warnings about dangling objects

Solution

  1. Step 1: Use git fsck to check repository integrity

    Start by running git fsck to detect any corrupted or missing objects.
  2. Step 2: Fix detected errors properly

    If errors appear, restore corrupted objects from backup or fetch from remote repositories. Dangling commits usually do not need deletion.
  3. Step 3: Verify fixes by rerunning git fsck

    Run git fsck again to confirm the repository is clean and healthy before release.
  4. Final Answer:

    Run git fsck, then if errors appear, restore corrupted objects from backup or remote, then run git fsck again -> Option B
  5. Quick Check:

    Check, fix, recheck = A [OK]
Hint: Check first, fix from backup, then recheck with git fsck [OK]
Common Mistakes:
  • Expecting automatic repair with non-existent flags
  • Deleting dangling commits unnecessarily
  • Ignoring warnings that could cause issues later
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard