1

Somewhen in my git history a change was implemented that broke feature A.

I don't know what is the commit and I'm not able to (easily) track the code to identify what caused the problem, because it's a very complex logic.

What I would like to do is.:

Go back to a old git commit (git checkout a9a9a9a) exec a command (script.rb) press enter git checkout next-commit

Once I'm back to the old commit i can't checkout to the next commit, I need to do git checkout master, git log, checkout the next sha, and git checkout nextsha1.

Is there any script or tool to easily do this?

Arnold Roa
  • 7,335
  • 5
  • 50
  • 69
  • 1
    `git bisect` is part of the solution. – siride Dec 14 '15 at 14:30
  • Possible duplicate of [How to use git bisect?](http://stackoverflow.com/questions/4713088/how-to-use-git-bisect) – Andrew C Dec 14 '15 at 20:44
  • Is that considered a duplicate? I was not aware of git bisect and my question is not "How to use git bisect" Is about how to find a bug introduced at an unknown commit in the git history. I asked because I searched about this and I was not able to find an answer. – Arnold Roa Dec 15 '15 at 12:04

1 Answers1

4

Yes: git provides git bisect for automatic discovery of wrong commit. As the manual explains, it uses a binary search algorithm (i.e., bisection) to find which commit in your project’s history introduced a bug. You use it by first telling it a "bad" commit that is known to contain the bug, and a "good" commit that is known to be before the bug was introduced. Then, it picks a commit between those two endpoints and asks you whether the selected commit is "good" or "bad". It continues narrowing down the range until it finds the exact commit that introduced the change.

Usage:

  • Initialize bisect:
    • git bisect reset master
    • git bisect start
    • git bisect good <commit>
    • git bisect bad <commit>
  • Mark a bisect as good/bad: git bisect (good|bad)
  • End bisecting: git bisect reset
Claudio
  • 10,614
  • 4
  • 31
  • 71
  • Incredible, I didn't know about this! it's fantastic! It seems that it also have `git bisect run ...` which automatically check the output code to find the bad commit – Arnold Roa Dec 14 '15 at 14:52