Urgent.News

What's breaking now, across thousands of outlets.

Tech

Twelve Commits, One Regression, Four Test Runs: git bisect run

The test fails on main . It passed a week ago. Twelve commits landed in between, most of them documentation, and nobody remembers which one touched the code. You could read all twelve diffs. Or you could let Git binary-search them in four steps. git bisect is the tool. It is older than most of the people who avoid it, and it needs three things: a commit you know is bad, a commit you know is good,…

Git bisect is a tool that allows developers to quickly find the commit that introduced a regression in their codebase. It requires three things: a commit that is known to be bad, a commit that is known to be good, and a way to test if a commit is good or bad. The bisect process involves checking out the middle commit between known good and bad commits, running the test, and reporting if the test passed or failed.

Git then halves the remaining range and repeats the process until it finds the first bad commit. The test must be able to run at any commit without depending on files that arrived later. The exit code of the test determines whether it is good or bad. Honest endpoints are important, as an incorrect good commit will lead to an incorrect result.

The test should focus on a specific thing, not the whole suite, to speed up the process. Git bisect can skip commits when they cannot be tested and works correctly with merges. It is easy to reuse a session and recover if a dirty tree is bisected.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Stop Stashing. Use a Second Working Directory for the Interruption.

"Can you look at the login bug on main? Five minutes." You are forty minutes into a feature, with edits in six files that do not compile yet.

  • Use Git worktrees to manage interruptions, preserving original branch context
  • Create second working directory sharing .git database for feature branch
  • Remove worktree after hotfix merge without affecting main branch

Undo a Git Commit: Two Questions Before You Type Anything

"How do I undo a commit?" has four correct answers and three wrong ones, and the difference is not the command — it is two questions you ask before typing anything: Where is the change?

  • If change is in working tree, use git restore file to revert edit
  • If staged change is unwanted, use git restore --staged file to unstage
  • If committed and not pushed, use git reset --soft HEAD~1 to move pointer

Git Remembers How You Resolved That Conflict — If You Let It

You rebase a long branch onto main . The first commit conflicts in config.yml ; you resolve it. The second commit touches the same lines and conflicts in exactly the same way . So does the third.

  • Git's rerere feature remembers past conflict resolutions.
  • Resolved conflicts in rebase make future merges easier.
  • Git requires manual inspection and staging after resolution.

More from Sunday 20 September →