1

I am trying to track down a specific bug in my code, but the trouble is the bug appeared somewhere in a block of commits where the only way to check if the commit breaks is commented out, so I can't see which commit it is.

I need to change one line of code, and have that line merge into several commits, can this be done?

Benjol
  • 63,995
  • 54
  • 186
  • 268
Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148

2 Answers2

4

The best way to find the first (or last) commit with a certain behaviour in a block of commits is to use git bisect. More specifically: git bisect run.

To automate the entire process you need to write a script which comments out the one line in question and then starts a test. the script should exit with code 0 if the code is good and code 1 if the code is bad.

For an example read here: http://www.metaltoad.com/blog/mechanizing-git-bisect-bug-hunting-lazy.

Lesmana
  • 25,663
  • 9
  • 82
  • 87
  • My issue is between the dependance of several files, but I am commenting out the printing of the result. The problem could be in one of around 10 files, but the result is echoed out in one place. Is `bisect run` that sophisticated? (I can't fathom it myself!!) – Mild Fuzz May 19 '11 at 12:38
  • @MildFuzz: `git bisect run` is utterly primitive, it just runs your script and checks the exit code. Whatever you need to do to find out whether the code is good or not needs to be done in your script. – Lesmana May 19 '11 at 12:45
  • In this instance, without a result coming back it's hard to imagine where to look. – Mild Fuzz May 19 '11 at 12:49
  • @Mild Fuzz, `git bisect` can also be run manually without a script. You do whatever you need to do to see if the problem is there or not, then run `git bisect good` or `git bisect bad` to go to the next step. – Karl Bielefeldt May 19 '11 at 16:25
0

Perhaps you just need to use git bisect?

Mike Weller
  • 45,401
  • 15
  • 131
  • 151