Updated: Automated "git bisect" will make your day

Posted . Visible to the public. Auto-destruct in 55 days

Added methods to keep the line number steady while you time-travel between commits:

Changes

  • So you're hunting down a regression (or just a bug) and want to use [`git bisect`](https://makandracards.com/makandra/943-how-to-use-git-bisect-to-find-bugs-and-regressions) to find out when it was introduced? Smart kid.
  • If you have a shell command ready to reveal if your current state is good or bad, you can have git do most of the work for you.
  • Using `git bisect run <your command>` you can tell git that your command will reveal the issue; git on the other hand will use the return value of that call to decide if the state is good or bad.
  • 1. First, start bisecting
  • git bisect start
  • 2. Then tell git which revisions are good and which are bad. You need to manually run your command for this, or just know which ones work and don't work.
  • git bisect bad
  • git bisect good abcdef1234
  • 3. Now tell git what to do
  • git bisect run bundle exec cucumber features/my.feature:42
  • 4. Wait for the results to come in: Git will bisect until it knows which commit was the first bad one.
  • 5. Finish bisect
  • git bisect reset
  • For more information, see [the original "git bisect" card](https://makandracards.com/makandra/943-how-to-use-git-bisect-to-find-bugs-and-regressions).
  • -> [important]
  • -> Mind that **your command needs to work across all revisions that you will be bisecting**. If you're referencing a test file that's under version control, make sure you always run the correct test; copying the file to a location outside of your repository might be a viable solution to keep the line number steady while you time-travel between commits.
  • +## The command must work across revisions
  • +
  • +Mind that **your command needs to work across all revisions that you will be bisecting**. If you're referencing a test file that's under version control, make sure you always run the correct test.There are several options to keep the **line number** steady while you time-travel between commits:
  • +
  • +- Copy the file to a new location that is not tracked by Git
  • +- [Run RSpec example by description](https://makandracards.com/makandra/47400-rspec-running-examples-name-running-single-shared-example)
  • +- [Run RSpec example by nesting index](https://makandracards.com/makandra/624970-rspec-executing-specs-example-nesting-index)
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2025-03-24 08:13)