Skip to content

Exercise Scavenger Hunt Solutions

Kenny Yu edited this page Oct 23, 2013 · 2 revisions

Git setup, and useful tidbits

First, let's setup your git identity:

git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS. Use whatever email you want."

Now, to add color to the output of your git commands:

git config --global color.ui auto

Finally, to add a very useful alias to visualize your git history:

git config --global alias.lg "log --graph --branches --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

This will add the useful alias git lg to visualize your git history:

lg

Scavenger Hunt

Make sure you've already done the Github forking exercise before doing this. Once you have the bootcamp-git directory on your computer, cd bootcamp-git.

You may find these commands useful for this exercise (note that commits are identified by the hashes when you type git lg, e.g. 032fdc36)

  • git log and git lg (setup the alias above)
  • git diff COMMIT1 COMMIT2 see all the changes between commits COMMIT1 and COMMIT2
  • git show COMMIT see what changes are introduced by a specific commit
  • git checkout COMMIT checkout the state of your project at an earlier commit. This allows you to examine the state of your project at some point in your project's history
  • git checkout master checkout the master branch again
  • git blame FILE who wrote each line of the file, and what commit introduced these changes?

For these exercises, please record the commands that you ran to see the answer, and also record the answer.

Question 1

What files existed as of commit 4b40046 (Adding aliases)? Hint: use the checkout command.

ANSWER

git checkout 4b40046
ls

baz.c     cat.c     dog.c     foo.c     goat.c    names.txt

Question 2

Make sure you are on master before starting this question (run git checkout master).

Which commit introduced the line bahhhhh into goat.c? Who wrote that line? Hint: look at the mystery commits!

ANSWER

git blame goat.c

8ad8411f (Kenny Yu 2013-09-14 14:21:47 -0400 1) goat
4a2e1f2b (Kenny Yu 2013-09-14 15:17:35 -0400 2) bahhhhh

Question 3

Make sure you're on master (git checkout master). Which commit removed the file foo.c?

ANSWER

git show c98ac8b

Finish Bootcamp

Go back to the main page.