I have a git repo with a combination of commits and merges containing multiple commits. I am trying to use git bisect to determine where a bug was introduced, but when the resulting commit points to a merge commit with a dozen different commits, this is not as helpful.
Is there a way to retroactively flatten a merge commit into its individual commits? Or is there some other method of performing a git bisect that will allow you to continue into the individual commits of a merge commit?
Yes. The key factor here is to recognize that when using git-bisect to track down a bug you do not necessarily have to run along the original branch, you can also create a copy branch that you slightly modify.
The modifications I think of are things like for instance
.gitignoreas the first commit in the bisect branch to make git status output clean.Now of course any change might mask/fix errors/add new errors, but if you keep the changes small/unrelated to what you are suspecting this should normally be fine. In worst case this will not work, but most likely it can identify the problem in a commit on the copy branch which you then need to correlate with the same commit on the original branch.
Now for the case you describe I assume the you have something like the following
and you want to bisect between
mainandTest-A. To flatten merge commit you can use interactive rebase which by default flattens the history1. So withthen you end up with a
Test-A.bisectbranch without merges, which you then can run bisect on (with the caveat that it is not exactly the same as the original branch, but this very seldomly is a significant problem).1 You need to specify
--rebase-mergesfor it to keep merge commits. I do include it by default in myrialias for interactive rebase.