Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get git bisect to ignore merged branches?

Tags:

git

git-bisect

I'm aware that git bisect is branch-aware by design, so that if between good commit, G, and bad commit, B, you merged in a branch, it needs to take those changes into consideration as well, as the bug may be contained in the branch.

In my case I have a dependency as a side branch and I merge in changes to my main project from time to time. The dependency can be considered a library that has a different way of running, different build-system etc. from my main project, but I still want recent changes from it via merges to the main branch.

The problem is then that while bisecting in this scenario, you end up on non-compilable commits in the commits from the dependency.

I would really just want to consider each branch merge as a single commit while doing the bisection.

A workaround I've found so far is making a list of valid commits G..B with git log --first-parent, and then while bisecting, do git bisect skip if the current commit isn't in that list. That takes a lot of time though (lots of files to checkout/change for each skip).

So the question is: Is there any way of doing --first-parent with git bisect or providing a list of commits i feel are valid to be able to avoid checking out branches I know already are not compilable? How do we only check the commits marked o in the diagram?

 G---o---o---o---o---o---o---B  main project branch    /       /       /    x---x---x---x---x            dependency            \ /             x'                 dependency project taskbranch 

Edit: added diagram for clarity

like image 377
tddtrying Avatar asked Apr 12 '11 15:04

tddtrying


People also ask

How do I stop a branch from merging?

Use git-reset or git merge --abort to cancel a merge that had conflicts. Please note that all the changes will be reset, and this operation cannot be reverted, so make sure to commit or git-stash all your changes before you start a merge.

What happens when branches are merged?

When you perform a merge, you effectively merge one branch into another—typically a feature branch or bug fix branch into a main branch such as master or develop. Not only will the code changes get merged in, but also all the commits that went into the feature branch.


1 Answers

I thought of one possible solution, but I'm still hoping to find something more elegant:

Mark all second-parents of all merges into the main branch as good

Marking all remote parents of each merge as good will consider all the commits preceding them as good (and as such skipped by bisect). This solution should also be generic enough to handle multiple merges from multiple branches, leaving only the commits on the main branch.

git rev-list --first-parent --merges --parents GOOD..BAD \ | sed 's/^[^ ][^ ]* [^ ][^ ]* //' \ | xargs git bisect good 

(replace GOOD and BAD with the relevant commits)

The regex in sed removes the first two commits of each line; the merge commit itself, and the first parent, leaving the rest of the parents (usually just the second one).

Given the history stated in the question, running the one-liner would give you:

 G---o---o---o---o---o---o---B  main project branch    /       /       /    G---x---G---x---G            dependency            \ /             x'                 dependency project taskbranch 

This would make bisect traverse only the commits on the main branch:

     o---o---o---o---o---o 

If any of the merged branches are indirectly the cause of the problem, it will be discovered when you test the merge commit via bisect, which could be reason to investigate further on that branch.

like image 58
2 revs, 2 users 95% Avatar answered Oct 05 '22 13:10

2 revs, 2 users 95%