Git Application Day
Five exercises, each starting from a broken or messy repository. Fix each one using the Git commands covered in class.
Repository: https://github.com/cmsc398w/git-application-day
Submission
After finishing each exercise, run the commands in its Submit section and paste the output into a file named answers.txt. Label each answer:
=== Exercise 1 ===<paste output here>
=== Exercise 2 ===<paste output here>Upload answers.txt and the entire application-day folder (zipped) to Gradescope. The zip must include the exercise/ subdirectory for each exercise.
Exercise 1: Merge Conflict (10 min)
cd 01-merge-conflictsource setup.shcd exerciseTwo branches both modified file.txt. Merge them so both lines end up in the file.
- Run
git log --oneline --graph --allto see where the branches diverged. - Merge
merge-conflict-branch1intomaster. - Open
file.txt, remove the conflict markers, and keep both lines. - Stage
file.txtand complete the merge. - Confirm with
git log --oneline --graph.
Submit: git log --oneline --graph and cat file.txt
Exercise 2: Reset (10 min)
cd 02-resetsource setup.shcd exerciseThe repo has 10 commits. Step backward using different reset modes, then use revert to undo a commit without rewriting history.
git log --onelineto see the starting state.git reset --soft HEAD~1— checkgit statusandgit log. Where did commit 10 go?git reset --mixed HEAD~1— what is different from--soft?git reset --hard HEAD~1— what changed compared to--mixed? Note that9.txtand10.txtare still present. Why?- You are now at commit 7. Run
git revert HEAD~1to undo commit 6. - Confirm with
git log --oneline. You should see 8 commits, the most recent a revert.
Submit: git log --oneline and ls
Exercise 3: Detached HEAD (10 min)
cd 03-detached-headsource setup.shcd exerciseYou checked out an old commit and HEAD is detached. Any commits made here are not attached to a branch and may be discarded.
git status— read git’s description of the state.git log --oneline --graph --all— find where HEAD andmasterare.- Create
hotfix.txt, add it, and commit with messagehotfix: emergency patch. - Run
git log --oneline --graph --allto see the floating commit. - Save it:
git branch hotfix - Switch back:
git checkout master - Cherry-pick the hotfix commit onto master.
- Confirm with
git log --oneline --graph --all.
Submit: git log --oneline --graph --all and ls
Exercise 4: Save My Commit (12 min)
cd 04-save-my-commitsource setup.shcd exerciseThe repo was reset to an early commit. holygrail.txt is gone from the working directory, but the commit that added it still exists in git’s object store — just not reachable from any branch. git reflog records every position HEAD has been at.
git log --onelineto see the short history.lsto confirmholygrail.txtis missing.git reflogto find the commit with messagefound the holy grail.git cherry-pick <sha>to bring that commit onto master.lsandcat holygrail.txtto confirm the file is back.
Submit: git log --oneline, ls, and cat holygrail.txt
Exercise 5: Bad Commit (10 min)
cd 05-bad-commitsource setup.shcd exerciseOne of five commits introduced badfile, which should never have been committed. Use git bisect to find it by binary search, then git revert to undo it without rewriting history.
A commit is bad if badfile exists. A commit is good if it does not.
git log --onelineto see the history.git bisect startgit bisect badto mark the current state.- Mark the first commit good:
git bisect good <sha> - For each commit git checks out, run
ls. Mark it good or bad accordingly. - When bisect identifies the culprit, run
git bisect reset. git revert <bad-commit-sha>— accept the default message.lsto confirmbadfileis gone.
Submit: git log --oneline and ls
Grading
Each exercise is worth 10 points (50 pts total).
| Exercise | What is checked |
|---|---|
| 1 | file.txt has no conflict markers, contains both lines, merge commit exists |
| 2 | Log has exactly 8 commits, most recent is a revert, 8.txt removed |
| 3 | HEAD is on master, hotfix branch exists, hotfix.txt is present, master has 5 commits |
| 4 | holygrail.txt exists and contains 42 |
| 5 | badfile is gone, a revert commit exists in the log |