kontur
kontur

Reputation: 5217

How to search for an old git commit for when a feature broke

while tracking down when a feature broke I identified a commit waaay in the past where the feature still worked. Now I'd like to incrementally checkout newer commits to see when the feature broke, without having to identify them by hash, but rather, relative to the hash I identified (where the feature still worked).

Is there a way to do something like this:

git checkout "COMMITHASH + X COMMITS NEWER (closer to master)"

or after having checked out a commit:

git checkout "X COMMITS NEWER (closer to master)"

Other solutions to the problem welcome as well, but still I am wondering if there is syntax like my pseudo statements above, something like HASH~1 but in inverse direction.

Upvotes: 2

Views: 195

Answers (1)

MrTux
MrTux

Reputation: 34022

Exactly for this use case there is the git bisect feature which uses a binary search.

See https://www.kernel.org/pub/software/scm/git/docs/git-bisect.html

Use it as follows:

  1. git bisect start to start bisecting
  2. git bisect bad to mark the HEAD as bad
  3. git bisect good HASH marks commit HASH as the last known good commit (can also be a git reference), e.g. a previous release

Then bisect will checkout the commit in the middle between the last known good commit and the last known bad commit. Do your testing here.

Depending on your results issue git bisect good or git bisect bad and git will go on until the faulty commit it found.

To stop bisecting issue git bisect reset

(if you have submodules you might have to update them after each step).

Upvotes: 8

Related Questions