Skip to content

Find the Bad Commit

Run the Find the Bad Commit MicroSim Fullscreen

About This MicroSim

The vendor-off test turns off every vendor and expects a score of 50. Today it gets 100. Somewhere in the last eight commits, a change broke it. You can run the test on any commit, but each run costs time, so the goal is to find the first bad commit in four runs or fewer.

Testing the middle commit first and then the middle of the half that's left is the idea behind git bisect. Once you've found the commit, you choose how to undo it. Only one of the three options removes the bad change and keeps the two working commits that came after it.

The commit IDs and messages are illustrative.

How to Use

  1. Click a commit to select it. Hover over any commit to read its message.
  2. Press Run test. The commit turns green for Pass or red for Fail, and the run counter goes up by one. You can also use the left and right arrow keys to select and Enter to run.
  3. When you know which commit broke the test, select it and press This one broke it.
  4. Choose one of the three undo options. The sim shows the history after your undo and the test result on the newest commit.
  5. Press Start over to try again.

Iframe Embed Code

You can add this MicroSim to any web page by adding this to your HTML:

<iframe src="https://arunbatchu.github.io/good-enough-engineering/sims/find-the-bad-commit/main.html"
        height="564px"
        width="100%"
        scrolling="no"></iframe>

Lesson Plan

Learning Objective

The learner will use test runs on a history of eight commits to find the first commit that broke a test, in four or fewer runs, and choose the undo that removes only that commit.

Grade Level

Adult professional (Good Enough Engineering)

Duration

10-15 minutes

Prerequisites

  • Commits as save points
  • Reading a Git history
  • The difference between reverting a commit and resetting a branch
  • One-way door decisions

Activities

  1. Exploration (5 min): Before running anything, predict which commit is most likely to have broken a scoring test, based on the messages alone.
  2. Guided Practice (5 min): Find the bad commit. Count your runs. If you used more than four, start over and test the middle commit first.
  3. Assessment (5 min): Choose the undo, then explain why resetting main would cost work that is fine.

Assessment

  • The first bad commit found in four or fewer runs, with no wrong guesses.
  • "Revert 9c03a5f" chosen on the first attempt.
  • The learner can say how many test runs a hundred commits would take by halves (about seven).

Common Misconceptions

  • The newest commit is the one that broke things.
  • Going back to an old commit is always the safe fix.
  • Testing every commit one by one is the only way to find the bad one.

References

  1. Chapter 5: Version Control - the sections "Git History" and "Revert and Rollback."
  2. Git documentation: git bisect - how Git searches a history by halves.
  3. Git documentation: git revert - adding a commit that undoes an earlier one.