basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Find where it broke: log, blame and bisect

    Something worked a week ago and doesn’t now. git log -S finds the commit where a line appeared or vanished, git blame who last changed a line and when, and git bisect halves its way to the breaking commit among forty in five or six checks — and can run the checks itself.

    Which tool to search with

    What you know What to search with
    a line that appeared or vanished: timeout: 0, a function name git log -S'timeout: 0'
    a line by pattern rather than exactly git log -G'timeout: [0-9]+'
    the file and roughly when git log --since=2026-10-10 -p -- app.yml
    a specific line of a file: who and why git blame -L 40,60 app.yml
    only “it used to work, now it doesn’t” git bisect

    By line: log -S and -G

    git log -S'timeout: 0' --oneline
    # 2f1396d step 27

    -S finds commits where the number of occurrences of a string changed: the line was added or removed. -G finds commits whose diff contains a line matching a regular expression. With -p you see the edits too.

    By a line of a file: blame

    git blame -L 1,1 app.yml
    # 2f1396d6 (t 2026-10-18 22:54:38 +0300 1) timeout: 0

    The hash, the author, the date, the line number. Then git show 2f1396d6: what else that commit changed and what its message says. This is exactly where a message that says “why” rather than “fix” pays off (Everyday git).

    • -w — don’t count whitespace and indentation as edits.
    • -C — find a line moved from another file.
    • git log -L 40,60:app.yml — the whole history of those lines, commit by commit.

    By halving: bisect

    There’s a good commit (it worked a week ago) and a bad one (now), with 40 commits between them. Git takes the middle, you check whether it’s good or bad, and half is discarded. 40 commits take 5–6 checks, 1,000 take 10.

    1. Start and mark the boundaries

      git bisect start
      git bisect bad                 # the current commit is bad
      git bisect good v1.2.0         # a tag, a hash or HEAD~40 is good
      # Bisecting: 19 revisions left to test after this (roughly 4 steps)
      # [9f4de09a…] step 20

      Git switched to a commit in the middle — HEAD is no longer on a branch, as intended.

    2. Check and mark

      Check however you like: build, run, open the page. Then:

      git bisect good    # works on this commit
      git bisect bad     # doesn't work
      git bisect skip    # can't check — something else is broken

      And so on, until git says:

      2f1396d65bf74b468767c2a9d12af792a120510c is the first 'bad' commit
          step 27
    3. Or let a script check

      If a command catches the breakage, git runs the search on its own. Exit code 0 means good, 1–124 and 126–127 bad, 125 skip:

      git bisect start HEAD v1.2.0
      git bisect run npm run build

      For this site — the build broke somewhere in the last couple dozen commits: git bisect run sh -c 'npm ci && npm run build'. For a config — a check for a line:

      git bisect run sh -c '! grep -q "timeout: 0" app.yml'
      # Bisecting: 9 revisions left to test after this (roughly 3 steps)
      # …
      # 2f1396d65bf74b468767c2a9d12af792a120510c is the first 'bad' commit
    4. Finish

      git bisect reset
      # Switched to branch 'main'

      Without reset, HEAD stays on the last commit checked.

    Once you’ve found the commit: git show to see what’s in it, git revert to undo it if it’s already on GitHub (Undo in git).

    If it doesn’t work

    git bisect heads the wrong way, and the commit it finds is innocent

    Cause
    One of the checks was marked wrong: good instead of bad — and half the history was discarded for nothing.
    Fix
    git bisect log lists every mark; git bisect reset and start over, or git bisect replay with a corrected log.

    bisect run marked everything bad, though old commits definitely work

    Cause
    The script fails for another reason: missing dependencies, a different Node version, a build cache.
    Fix
    Try the script by hand on a known-good commit: git switch --detach a1b2c3 && npm ci && npm run build.

    A commit doesn’t build at all — neither good nor bad

    Cause
    An intermediate commit with a build broken for another reason.
    Fix
    git bisect skip — git takes a neighbouring one. In a script, exit with code 125.

    git blame points to a commit that only reformatted the file

    Cause
    The last commit to touch the line changed indentation or line wrapping.
    Fix
    git blame -w ignores whitespace; for mass reformatting, list the commits in .git-blame-ignore-revs and run git config blame.ignoreRevsFile .git-blame-ignore-revs.

    After bisect the project is in an odd state, and git status says HEAD detached

    Cause
    The search wasn’t finished with reset: HEAD stayed on the commit being checked.
    Fix
    git bisect reset takes you back to the branch you started from.

    How to check

    Is the commit you found in fact to blame? Check it and its parent:

    git switch --detach 2f1396d~1 && npm run build    # the parent builds
    git switch --detach 2f1396d   && npm run build    # the commit itself doesn't
    git switch main