2

My usual workflow when starting a git bisect session is:

git bisect start          # start a bisect session
git bisect bad            # I noticed that the current state is broken

Now, often I know that things worked in the past, but I don't know yet which version was good, so I usually want to revert my working tree to an older state, build, test, repeat until I find a working version which I can mark with git bisect good.

What's the best way to do the "revert my working tree to an older state" step? git reset --hard <some_good_rev>? git checkout <some_good_rev>? Something else? Please justify your answer.

2 Answers 2

8

I usually don't know where the good rev is, so I've got to find it. Guess how far back might be good. Let's say, 32 revs. Starting from the tip of a branch, and with clean working directories:

$ git checkout HEAD~32

Run the test. If it's a good rev, start bisecting. If it's not, go back some more:

$ git checkout HEAD~32

Rinse, lather, repeat.

Why "git checkout?" Because "git reset" will change which commit the branch points to as its "tip", but git checkout will not.

1
  • Ah, the "~n" notation is a nice trick here; I wondered whether 'checkout' works because it gives me a 'detached head'. I wasn't sure bisect likes that, but apparently it does. Cheers! Jan 20, 2010 at 10:03
1

If you don't know for sure any version where the functionality worked (the commit that introduced the functionality?), you seem to lose a lot (all?) of the benefit of a bisect. If you do know that there was at least one commit where the functionality worked, even if it isn't necessarily the most recent commit where the functionality worked, just flag that one as good. Otherwise, you're basically doing a bisect yourself.

4
  • I apologize for the imprecision; I meant to imply that I do know that some past version worked - I just don't know which. I added that now to my question. Jan 20, 2010 at 10:04
  • @FrerichRaabe: jamessan's point still stands. If you don't know any commit where the feature worked, you cannot use bisect. Normally at least the commit that introduced a feature should be a "good" commit - after all, you did test the feature before committing, didn't you?
    – sleske
    May 4, 2012 at 19:53
  • @sleske: This is a large proejct with two dozen developers, and it's not realistic to expect that every developer tested every possible platform (this project is portable across a wide range of operating systems). Alas, the automatic test suite doesn't catch every possible problem either - and even if it would: there's often no single commit which implements a feature (usually it's a series of commits which are rebased on top of master, i.e. there is no merge commit). Feb 7, 2013 at 7:53
  • @FrerichRaabe: Yes, for complex functionality the last "good" version can be hard to pin down. Then you'll just have to keep trying different versions, as suggested in Wayne Conrad's answer.
    – sleske
    Feb 10, 2013 at 13:10

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.