>_ IzzyLab

Hands-on task

This task is step 17 of the course “Git: rewriting and rescuing history”

Find the first bad commit

hard~12 min

In /root/repo there is a linear history of eight commits (c0…c7). In each commit the file app.txt is overwritten. At some commit a bug marker appeared in app.txt and stayed in all subsequent commits — that is, all the early commits are "good", and starting from some point they're "bad".

Find the first bad commit (the one where bug appeared for the first time) and write its full hash into the file /root/answer.txt (as a single line). The very first commit c0 is known to be good, and the tip of the branch is known to be bad.

What you'll practise:
  • git bisect
  • regression hunting
  • binary search
  • git rev-parse
  • commit hashes

Topic breakdown

When a defect has "crept" into the history at an unknown commit, going through dozens of revisions by hand is inefficient — it's better to reduce the number of checks to a logarithm. For this git has a built-in binary-search mechanism over the range between a known-good and a known-bad boundary: at each step it hands you a commit from the middle, you tell it the verdict (good/bad), and it halves the interval. The check can also be automated with a predicate script so git runs the whole range itself. The full hash of the right commit is obtained via git rev-parse.

What's checked

  1. a full commit hash is written in answer.txt
  2. it is exactly the first bad commit

What it looks like