threads / discuss / 40992

git bisect with temporary commits

Subject: git bisect with temporary commits

## tl;dr

9 messages between Dec 14, 2015 and Dec 14, 2015.

replies: 8people: 4as markdown or json

Florian Bruhin· Dec 14, 2015, 16:37 UTC · lore
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
-- 
http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
Andreas Schwab· Dec 14, 2015, 18:08 UTC · re: Florian Bruhin · lore

Re: git bisect with temporary commits

Florian Bruhin <me@the-compiler.org> writes:
Show 10 quoted lines
> 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.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Florian Bruhin· Dec 14, 2015, 18:22 UTC · re: Andreas Schwab · lore

Re: git bisect with temporary commits

* Andreas Schwab <schwab@linux-m68k.org> [2015-12-14 19:08:48 +0100]:
Show 15 quoted lines
> Florian Bruhin <me@the-compiler.org> writes:
> 
> > 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.

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
-- 
http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
Junio C Hamano· Dec 14, 2015, 19:21 UTC · re: Florian Bruhin · lore

Re: git bisect with temporary commits

Florian Bruhin <me@the-compiler.org> writes:
Show 23 quoted lines
> * Andreas Schwab <schwab@linux-m68k.org> [2015-12-14 19:08:48 +0100]:
>> Florian Bruhin <me@the-compiler.org> writes:
>> 
>> > 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.
>
> 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.

Florian Bruhin· Dec 14, 2015, 19:38 UTC · re: Junio C Hamano · lore

Re: git bisect with temporary commits

* Junio C Hamano <gitster@pobox.com> [2015-12-14 11:21:06 -0800]:
Show 31 quoted lines
> Florian Bruhin <me@the-compiler.org> writes:
> 
> > * Andreas Schwab <schwab@linux-m68k.org> [2015-12-14 19:08:48 +0100]:
> >> Florian Bruhin <me@the-compiler.org> writes:
> >> 
> >> > 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.
> >
> > 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.
That makes sense - thanks for the explanation!
Florian
-- 
http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
Andreas Schwab· Dec 14, 2015, 20:17 UTC · re: Florian Bruhin · lore

Re: git bisect with temporary commits

Florian Bruhin <me@the-compiler.org> writes:
> 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.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Jeff King· Dec 14, 2015, 21:09 UTC · re: Andreas Schwab · lore

Re: git bisect with temporary commits

On Mon, Dec 14, 2015 at 07:08:48PM +0100, Andreas Schwab wrote:
Show 15 quoted lines
> Florian Bruhin <me@the-compiler.org> writes:
> 
> > 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.

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
Junio C Hamano· Dec 14, 2015, 21:17 UTC · re: Jeff King · lore

Re: git bisect with temporary commits

Jeff King <peff@peff.net> writes:
Show 6 quoted 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)
Jeff King· Dec 14, 2015, 21:26 UTC · re: Junio C Hamano · lore

Re: git bisect with temporary commits

On Mon, Dec 14, 2015 at 01:17:03PM -0800, Junio C Hamano wrote:
Show 17 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> >> 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)

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

← back to recent threads