Lab 4: Git Operations¶
| Field | Value |
|---|---|
| Tier | 1 — Foundations |
| Estimated Time | 30 minutes |
| Prerequisites | Git installed |
| Auto-Grade | Yes |
Scenario¶
It is Friday afternoon and four different developers have managed to create four
different git disasters in the same repository. One developer detached HEAD while
experimenting with an old tag and now cannot find their recent work. Another
force-pushed to main and wiped out three commits that the team needs. A third
developer started a merge, hit conflicts, and then ran git checkout . in a panic
— the merge is stuck in a half-resolved state. A fourth developer accidentally
deleted a branch containing an unreleased feature, and the commit is dangling.
The repository also has a corrupted index file that causes git status to fail.
You are the only person left in the office. Fix every disaster, recover every
commit, and leave the repository in a clean, working state.
Objectives¶
- Recover from the detached HEAD state and preserve the work on a branch
- Restore the three commits that were force-pushed away (find them in reflog)
- Resolve the stuck merge conflict and complete the merge
- Recover the lost feature branch commit from the dangling object
- Fix the corrupted index so
git statusworks cleanly
Setup¶
Creates a git repository with multiple disasters under /tmp/lab-git-operations/.
Hints¶
Hint 1: Detached HEAD
Use `git reflog` to find the commit you were on. Then `git checkout -b recovery-branchHint 2: Force-pushed commits
`git reflog` shows all recent HEAD movements. Find the SHA before the force-push and use `git reset --hardHint 3: Stuck merge
Check `git status` for unmerged paths. Edit the conflicted files, remove the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`), then `git add` and `git commit`.Hint 4: Dangling commits
Use `git fsck --lost-found` to find dangling commits. Then `git branch recovered-featureHint 5: Corrupted index
Remove the corrupted index file: `rm .git/index`, then rebuild it with `git reset HEAD` or `git read-tree HEAD`.Grading¶
Solution¶
See the solution/ directory for step-by-step recovery commands.