Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I use git bisect to find the first GOOD commit?

Tags:

git

bisect

I have the following problem:

  • the version at master works fine
  • the version of the last tag before master (say last) has a bug
  • a colleague needs a patch for his last revision for that certain bug

Okay. Let's ask our friend git bisect for the revision that fixed the bug:

git bisect start git bisect bad last git bisect good master 

But that's not going to work:

Some good revs are not ancestor of the bad rev.
git bisect cannot work properly in this case.
Maybe you mistake good and bad revs?

Any hints to overcome this? Did I miss something in the docs?

like image 891
eckes Avatar asked Mar 14 '13 10:03

eckes


People also ask

What operation you can use on git to find the first bad version?

For example, git bisect reset bisect/bad will check out the first bad revision, while git bisect reset HEAD will leave you on the current bisection commit and avoid switching commits at all.

How do I remove a bad commit in git bisect?

Use git log to check the previous commits. Use Git Bisect to find the commit in which line 2 is changed from 'b = 20' to 'b = 0.00000'. Remove the bad commit by using Git Revert. Leave the commit message as is.

What is git bisect and how do you use it?

The git bisect command is used to discover the commit that has introduced a bug in the code. It helps track down the commit where the code works and the commit where it does not, hence, tracking down the commit that introduced the bug into the code.

Which command is used to find the commit that introduced a bug?

Git Bisect — use binary search to find the commit that introduced a bug. Git Bisect is a handy tool used for debugging, it uses Binary Search to go through the previous commits to find out the exact commit that introduced the regression/bug in the code.


1 Answers

As of git 2.7, you can use the arguments --term-old and --term-new.

For instance, you can identify a problem-fixing commit thus:

git bisect start --term-new=fixed --term-old=unfixed git bisect fixed master git bisect unfixed $some-old-sha1 

As you test, say git bisect fixed or git bisect unfixed as appropriate.

Old answer, for versions of git prior to 2.7

Instead of temporarily training yourself to think that bad means good and good means bad, why not create some aliases?

In ~/.gitconfig add the following:

[alias]         bisect-fixed = bisect bad         bisect-unfixed = bisect good 

You can start identifying a problem-fixing commit thus:

$ git bisect start $ git bisect-fixed master $ git bisect-unfixed $some-old-sha1 

As you test, say git bisect-fixed or git bisect-unfixed as appropriate.

like image 136
Michael Wolf Avatar answered Sep 17 '22 14:09

Michael Wolf