Debugging with git

The setup script is located in the git.zip file in the exercsises folder.

Run ./debugging.sh for setup!

git blame

git blame annotates each line with commit it was last changed. It can also detect movements and copies of lines.

Instructions

  1. Run git blame -C file2.txt
  2. Run git show to show the last commit
  3. Run git blame file2.txt

Questions

Answers

git bisect

Imagine the following situation. Sometime during the last weeks a subtle bug was introduced. You have no idea when and where this happened. Lucky for you, the team does rather small commits and now it is only a question to find the specific commit. Even better, there is a simple, automatic test to detect the bug. git bisect helps you to find this commit fast!

Preparations

  1. Run ./test.sh and watch the test fail
  2. We assume the commit with add new stuff to file1 was a good commit. Run git log --oneline to find the commit hash
  3. Run git checkout commitHash to check this out this revision (we detach the head and check out this revision)
  4. Run ./test.sh again and watch if succeed
  5. Run git checkout debugging to switch to back to the debugging branches HEAD

Bisecting

HINT: There are two aliases defined

  1. Run git bisect start
  2. Mark the current HEAD as bad with git bisect bad
  3. Mark the commitHash from the good commit as good with git bisect good commitHash
  4. Now we start the loop: Run ./test.sh and then either git bisect bad or git bisect good
  5. Stop when a commit is printed
  6. Run git bisect reset to exit bisect mode

Questions

Answers