Git disasters · Chapter 14 of 14

Find the commit that broke it

Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Merges and detective work
  • 3 tasks
  • Git
  • In the all labs plan

The first 2 chapters of Git disasters are free. This one comes with the all labs plan.

What you build: 3 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    See what happened: bisect to the first bad commit

    Ten masala chai (400 rupees) should bill 360 with the bulk discount. On main they bill 324. The tag v1.4 billed them right, and main is 30 commits later. Find the first bad commit with git bisect run.

    1. Write a small script, outside Git (untracked). It exits 0 when the commit checked out bills 10 cups at 40 as 360, and 1 when it does not.

    2. Start git bisect between main (bad) and v1.4 (good).

    3. Run git bisect run with your script. It prints the first bad commit.

    4. Write that hash into answer.txt, in the case's folder. Then reset bisect.

    To pass: answer.txt has the hash of the first bad commit (7 characters or more), and no other hash. You also typed git bisect run in the terminal, in the case's folder.

  2. Task 2

    Fix: bill 10 cups right on GitHub

    Make main bill 10 cups right again, on GitHub. Main is shared, so fix it with a new commit on top.

    1. Look at what the first bad commit changed.

    2. Make a new commit that undoes it, or fix bill.js by hand.

    3. Run your script and node --test.

    4. Push main to GitHub. Use a normal push, not a force push.

    To pass: on GitHub's main, 10 masala chai (400) bill 360, and 4 cutting chai (100) bill 100. node --test passes there. GitHub's main still has the commit "Count bulk orders weekly".

  3. Task 3

    Guard it: a test that orders 10 cups

    Add a test, so this bug cannot come back without anyone seeing it.

    1. Write bulk.test.js in the top folder of the repository. It is a node --test file.

    2. It imports total from ./bill.js. Check the exact total for 10 cups, and for a small order too.

    3. Run node --test. Commit the file on main and push it.

    To pass: GitHub's main has bulk.test.js. The Check runs it with three versions of bill.js. With the bill.js from just before the bad commit, every test must pass. With the bill.js from the bad commit, at least one test must fail. With a bill.js that never gives the bulk discount, at least one test must fail. Each run must end within a few seconds.

What you will learn

  • See what happened: bisect to the first bad commit
  • Fix: bill 10 cups right on GitHub
  • Guard it: a test that orders 10 cups

More in Merges and detective work

Build "Find the commit that broke it" yourself

Bunty is Tapri's new junior developer, and Kabir keeps handing you the Git incidents left behind. Each is a disaster interviews love to ask about. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Git disasters are free. This one comes with the all labs plan.