Figuring out what went wrong


I was working on a large refactor with hundreds of changed files, with six commits on the branch past main. But somehow something had broken that seemed totally unrelated to my work! When I would git checkout main everything was fine, and when I would git checkout mybranch it had broken. Specifically, some Typescript types for a third-party library were no longer resolving—and my changes involved neither the third party library nor the Typescript setup.

First thing I did was see if I had changed any of the build config files, anything at the top level that could make strange things happen. git checkout main yarn.lock and things like that. No dice.

How I ended up resolving the issue was the following:

  1. Create a new branch, git checkout -b mybranch-debug
  2. Do an interactive rebase with git rebase -i and fixup everything into a single commit
  3. Split that commit into one commit per file using this script, resulting in hundreds of commits.
  4. git bisect to find the guilty file
  5. Delete stuff from that file until it's evident what caused the problem

Hope that helps someone else figure their way out of a baffling problem!