In git, we have bisect to conveniently find the first bad commit, in this way:
git bisect start linux-next/master v2.6.26-rc8
git bisect run make kernel/fork.o
But the prerequisite is I know which old commit is good. In this example, it is v2.6.26-rc8.
What happens if I don't know which commit is good?
Is it possible to write a script, to reversely loop through the git commits, begin from current HEAD, from latest to oldest, and automatically test each commit, until the first good?
git bisectdoes a binary search through the commit history.goodandbadsimply provide boundaries for this search. Git then searches within that range for a commit which is "bad" and the previous one was "good".All that matters is the "good" commit is before the feature broke, and the "bad" commit is after the feature broke. If you're not sure when the feature broke, pick a commit before the feature was introduced.
If you're not sure, pick a really old commit. You can even pick the first commit. This isn't as absurd as it sounds. Binary searches are very efficient; 10,000 commits can be searched in just log2(10000) tries or 13 tries.
For example, let's say your commit history looks like this.
You know the feature is broken now, you don't know when it was good, but you do know it was introduced at d. Pick c, the commit immediately before the feature was introduced, as the "good" commit.
Then
git bisectwill do a binary search ofd - e - f - g - huntil it finds a bad commit immediately after a good one.In this case it will start with f. Let's say that's bad.
Git assumes everything after f is also bad. Then it might try d. Let's say that's good.
Then it will try e. Let's say that's bad.
e broke the feature.