Skip to content

cmsc398w/git_application_day

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git Application Day

Each exercise starts with a broken or messy repository. Your job is to fix it using the git commands you have learned. Read the setup output and the starting state of the repo before doing anything.

Submission

When you finish each exercise, run the commands listed in the Submit section for that exercise and paste the output into a plain text file named answers.txt. Label each answer clearly.

=== 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 you completed.


Exercise 1: Merge Conflict (10 min)

Setup

cd 01-merge-conflict
source setup.sh
cd exercise

Background

Two branches both added a file called file.txt with different content. Git cannot merge them automatically. Both lines need to end up in the file.

Tasks

  1. Run git log --oneline --graph --all to see the two branches and where they diverged.
  2. Merge merge-conflict-branch1 into master.
  3. Open file.txt in an editor. Remove the conflict markers and keep both lines.
  4. Stage file.txt and complete the merge.
  5. Run git log --oneline --graph to confirm the merge commit is there.

Submit

git log --oneline --graph
cat file.txt

Exercise 2: Reset (10 min)

Setup

cd 02-reset
source setup.sh
cd exercise

Background

The repository has 10 commits, numbered 1 through 10. You will use reset to step backward through history and observe what changes in each mode. Then you will use revert to undo a specific commit without rewriting history.

Tasks

  1. Run git log --oneline to see the starting state.
  2. Run git reset --soft HEAD~1. Check git status and git log --oneline. Where did commit 10 go?
  3. Run git reset --mixed HEAD~1. Check git status and git log --oneline. What is different from --soft?
  4. Run git reset --hard HEAD~1. Check git status and git log --oneline. What changed compared to --mixed? Note that 9.txt and 10.txt are still present even though their commits are gone. Why?
  5. You are now at commit 7. Run git revert HEAD~1 to undo commit 6. Accept the default commit message.
  6. Run git log --oneline. You should see 8 commits. The most recent should be a revert commit.

Submit

git log --oneline
ls

Exercise 3: Detached HEAD (10 min)

Setup

cd 03-detached-head
source setup.sh
cd exercise

Background

You opened an old commit to inspect something and git is now telling you that HEAD is detached. Any commits you make in this state are not attached to any branch and git will warn they may be discarded.

Tasks

  1. Run git status. Read git's description of the current state.
  2. Run git log --oneline --graph --all. Find where HEAD is and where master is.
  3. Create a file called hotfix.txt, add it, and commit it with the message hotfix: emergency patch. This commit is now floating with no branch pointing to it.
  4. Run git log --oneline --graph --all again to see the floating commit.
  5. Create a branch called hotfix at your current position to save that commit: git branch hotfix
  6. Switch back to master: git checkout master
  7. Cherry-pick the hotfix commit onto master.
  8. Run git log --oneline --graph --all to confirm the final state.

Submit

git log --oneline --graph --all
ls

Exercise 4: Save My Commit (12 min)

Setup

cd 04-save-my-commit
source setup.sh
cd exercise

Background

The repository was reset to an early commit. A file called holygrail.txt is gone from the working directory. The commit that added it still exists in git's object store, it just is not reachable from any branch. git reflog records every position HEAD has been at, including ones that are no longer in the branch history.

Tasks

  1. Run git log --oneline to see the current short history.
  2. Run ls to confirm holygrail.txt is missing.
  3. Run git reflog to find the commit with message found the holy grail.
  4. Use git cherry-pick <sha> to bring that commit onto master.
  5. Run ls and cat holygrail.txt to confirm the file is back.

Submit

git log --oneline
ls
cat holygrail.txt

Exercise 5: Bad Commit (10 min)

Setup

cd 05-bad-commit
source setup.sh
cd exercise

Background

One of the five commits on master introduced a file called badfile that should never have been committed. You do not know which commit it was. Use git bisect to find it by binary search, then use git revert to undo it without rewriting history.

A commit is bad if badfile exists in the working directory. A commit is good if it does not.

Tasks

  1. Run git log --oneline to see the history.
  2. Start bisect: git bisect start
  3. Mark the current state as bad: git bisect bad
  4. Find the first commit SHA from git log --oneline and mark it good: git bisect good <sha>
  5. For each commit git checks out, run ls to check whether badfile exists. Mark it git bisect good or git bisect bad accordingly.
  6. When bisect identifies the bad commit, run git bisect reset to return to HEAD.
  7. Use git revert <bad-commit-sha> to revert the bad commit. Accept the default commit message.
  8. Run ls to confirm badfile is gone. Run git log --oneline to confirm the revert commit is there.

Submit

git log --oneline
ls

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages