Skip to contentSkip to conversation

git bisect with temporary commits

DISCUSSION Florian Bruhin 4 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi!

Today I bisected a bug which required cherry-picking an (unrelated) compile fix later in the history so I could test the commits.

After testing a commit, I didn't reset to the commit before the cherry-picked one, which seemed to work well, but doesn't in my minimal example:

    $ git init
    $ echo 'good and does not compile' > file
    $ git add file && git commit -m 'good and does not compile'
    $ echo again >> file && git commit -am 'still good and does not compile'
    $ echo 'bad and compiles' > file && git commit -am 'bad and compiles'
    $ git log --oneline --decorate
    97f9214 (HEAD, master) bad and compiles
    981e109 still good and does not compile
    753ed25 good and does not compile

Now I start bisecting and cherry-pick the compile fix in master:

    $ git bisect start
    $ git bisect bad master
    $ git bisect good master~2  # 753ed25
    Bisecting: 0 revisions left to test after this (roughly 0 steps)
    [981e1093dae24b37189bcba2dd848b0c3388080c] still good and does not compile
    florian@ws042:~/tmp/bisect1$ git cherry-pick master
    [detached HEAD b49872b] bad and compiles
     Date: Mon Dec 14 17:26:51 2015 +0100
      1 file changed, 1 insertion(+), 2 deletions(-)

Now when trying to say it's good (and forgetting to remove the temporary commits), I get this:

    $ git bisect good
    Bisecting: a merge base must be tested
    [981e1093dae24b37189bcba2dd848b0c3388080c] still good and does not compile

Is this intended behaviour? Shouldn't git either do a reset to the commit we're currently bisecting, or warn the user as it was probably unintended to add new commits?

Currently it seems bisect just treats the current HEAD as good, and then the bisect algorithm tries to (I think) select a commit between the currently bisected one and the (temporary) HEAD?

When I used it today, it actually seemed to work well until I hit an *actual* merge base, and then it started to bisect something unexpected, which got me a bit confused ;)

Florian

Signature · 3 lines
http://www.the-compiler.org | [email protected] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
#1 lore raw
Quoted 10 lines · Florian Bruhin

Now when trying to say it's good (and forgetting to remove the temporary commits), I get this:

    $ git bisect good
    Bisecting: a merge base must be tested
    [981e1093dae24b37189bcba2dd848b0c3388080c] still good and does not compile

Is this intended behaviour? Shouldn't git either do a reset to the commit we're currently bisecting, or warn the user as it was probably unintended to add new commits?

You should instead tell git that HEAD^ is good, since that is what git asked you to test.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#2 lore raw
Quoted 9 lines · Andreas Schwab
Quoted 7 lines · Florian Bruhin

Now when trying to say it's good (and forgetting to remove the temporary commits), I get this:

    $ git bisect good
    Bisecting: a merge base must be tested
    [981e1093dae24b37189bcba2dd848b0c3388080c] still good and does not compile
Quoted 6 lines
Quoted 3 lines

Is this intended behaviour? Shouldn't git either do a reset to the commit we're currently bisecting, or warn the user as it was probably unintended to add new commits?

You should instead tell git that HEAD^ is good, since that is what git asked you to test.

I see - but wouldn't it make more sense for a "git bisect good" (or bad, respectively) without arguments to assume I mean the commit bisect checked out for me, not HEAD?

I don't see any scenario where the current behaviour would make sense, but I might be missing something.

Florian

Signature · 3 lines
http://www.the-compiler.org | [email protected] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
#3 lore raw
Quoted 3 lines · Florian Bruhin

I see - but wouldn't it make more sense for a "git bisect good" (or bad, respectively) without arguments to assume I mean the commit bisect checked out for me, not HEAD?

The problem is that there is nothing that marks the originally checked out commit except by being pointed to by HEAD. Also, testing a different commit as the one suggested by git can be useful when skipping over commits that are known to fail for unrelated reasons (see "Avoiding testing a commit" in git-bisect(1)).

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#4 lore raw
In reply to Florian Bruhin
Quoted 17 lines · Florian Bruhin
Quoted 9 lines · Andreas Schwab
Quoted 7 lines · Florian Bruhin

Now when trying to say it's good (and forgetting to remove the temporary commits), I get this:

    $ git bisect good
    Bisecting: a merge base must be tested
    [981e1093dae24b37189bcba2dd848b0c3388080c] still good and does not compile
Quoted 6 lines
Quoted 3 lines

Is this intended behaviour? Shouldn't git either do a reset to the commit we're currently bisecting, or warn the user as it was probably unintended to add new commits?

You should instead tell git that HEAD^ is good, since that is what git asked you to test.

Quoted 6 lines

I see - but wouldn't it make more sense for a "git bisect good" (or bad, respectively) without arguments to assume I mean the commit bisect checked out for me, not HEAD?

I don't see any scenario where the current behaviour would make sense, but I might be missing something.

When the commit "bisect" checked out is untestable, the user can freely go to another commit, e.g. "git reset --hard HEAD^" to go back one step, and then test it instead. "git bisect good" has to mark the then-current HEAD, not the commit that was checked out, for this to work.

#5 lore raw
Quoted 23 lines · Junio C Hamano
Quoted 21 lines · Florian Bruhin
Quoted 9 lines · Andreas Schwab
Quoted 7 lines · Florian Bruhin

Now when trying to say it's good (and forgetting to remove the temporary commits), I get this:

    $ git bisect good
    Bisecting: a merge base must be tested
    [981e1093dae24b37189bcba2dd848b0c3388080c] still good and does not compile
Quoted 6 lines
Quoted 3 lines

Is this intended behaviour? Shouldn't git either do a reset to the commit we're currently bisecting, or warn the user as it was probably unintended to add new commits?

You should instead tell git that HEAD^ is good, since that is what git asked you to test.

I see - but wouldn't it make more sense for a "git bisect good" (or bad, respectively) without arguments to assume I mean the commit bisect checked out for me, not HEAD?

Quoted 8 lines
Quoted 2 lines

I don't see any scenario where the current behaviour would make sense, but I might be missing something.

When the commit "bisect" checked out is untestable, the user can freely go to another commit, e.g. "git reset --hard HEAD^" to go back one step, and then test it instead. "git bisect good" has to mark the then-current HEAD, not the commit that was checked out, for this to work.

That makes sense - thanks for the explanation!

Florian

Signature · 3 lines
http://www.the-compiler.org | [email protected] (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
#6 lore raw
In reply to Andreas Schwab
Quoted 9 lines · Andreas Schwab
Quoted 7 lines · Florian Bruhin

Now when trying to say it's good (and forgetting to remove the temporary commits), I get this:

    $ git bisect good
    Bisecting: a merge base must be tested
    [981e1093dae24b37189bcba2dd848b0c3388080c] still good and does not compile
Quoted 6 lines
Quoted 3 lines

Is this intended behaviour? Shouldn't git either do a reset to the commit we're currently bisecting, or warn the user as it was probably unintended to add new commits?

You should instead tell git that HEAD^ is good, since that is what git asked you to test.

Another alternative is to use "git cherry-pick -n" to create a working tree state that you can test, but leave HEAD at the original commit. Then "git bisect good" does the right thing.

It's the same principle and I don't think there is a reason to prefer one over the other. I just find it harder to screw up, as I usually script the build/test, so I can stick the cherry-pick there and not have to remember it on each "good/bad" report.

-Peff

#7 lore raw
Quoted 6 lines · Jeff King
Quoted 2 lines

You should instead tell git that HEAD^ is good, since that is what git asked you to test.

Another alternative is to use "git cherry-pick -n" to create a working tree state that you can test, but leave HEAD at the original commit. Then "git bisect good" does the right thing.

I was about to say the same, and "bisect good" at that point does mark the correct commit, but does it always do the right thing? I think the procedure must be

git cherry-pick -n $the_fixup
test
git reset --hard
git bisect good (or bad)

for it to always work, which is not all that different from

git cherry-pick $the_fixup
test
git reset --hard HEAD^
git bisect good (or bad)

#8 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Jeff King
Quoted 2 lines

You should instead tell git that HEAD^ is good, since that is what git asked you to test.

Another alternative is to use "git cherry-pick -n" to create a working tree state that you can test, but leave HEAD at the original commit. Then "git bisect good" does the right thing.

Quoted 8 lines

I was about to say the same, and "bisect good" at that point does mark the correct commit, but does it always do the right thing? I think the procedure must be

git cherry-pick -n $the_fixup
test
git reset --hard
git bisect good (or bad)

Hmm, you're right. I assumed "git bisect good" would do the equivalent of "git checkout -f", but it doesn't. I guess it has been long enough since I have had to cherry-pick a fix that I completely forgot that bit.

It might be convenient if bisect did pass "-f" to checkout, but I guess it would also be destructive if you had hand-tweaks you forgot to save.

-Peff