# git bisect with temporary commits

9 messages from 2015-12-14 to 2015-12-14. Participants: Florian Bruhin, Andreas Schwab, Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/40992

## Florian Bruhin, 2015-12-14 16:37

Subject: git bisect with temporary commits
Message-ID: <20151214163726.GY13519@tonks>
URL: https://gitlist.dev/e/20151214163726.GY13519%40tonks

```
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, 2015-12-14 18:08

Subject: Re: git bisect with temporary commits
Message-ID: <87si34hphr.fsf@igel.home>
URL: https://gitlist.dev/e/87si34hphr.fsf%40igel.home
In-Reply-To: <20151214163726.GY13519@tonks>

```
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.

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, 2015-12-14 18:22

Subject: Re: git bisect with temporary commits
Message-ID: <20151214182255.GB13519@tonks>
URL: https://gitlist.dev/e/20151214182255.GB13519%40tonks
In-Reply-To: <87si34hphr.fsf@igel.home>

```
* 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.

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, 2015-12-14 19:21

Subject: Re: git bisect with temporary commits
Message-ID: <xmqqa8pckfa5.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqa8pckfa5.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20151214182255.GB13519@tonks>

```
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.

```

## Florian Bruhin, 2015-12-14 19:38

Subject: Re: git bisect with temporary commits
Message-ID: <20151214193802.GD13519@tonks>
URL: https://gitlist.dev/e/20151214193802.GD13519%40tonks
In-Reply-To: <xmqqa8pckfa5.fsf@gitster.mtv.corp.google.com>

```
* Junio C Hamano <gitster@pobox.com> [2015-12-14 11:21:06 -0800]:
> 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, 2015-12-14 20:17

Subject: Re: git bisect with temporary commits
Message-ID: <87lh8whjj2.fsf@igel.home>
URL: https://gitlist.dev/e/87lh8whjj2.fsf%40igel.home
In-Reply-To: <20151214182255.GB13519@tonks>

```
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, 2015-12-14 21:09

Subject: Re: git bisect with temporary commits
Message-ID: <20151214210936.GD14788@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20151214210936.GD14788%40sigill.intra.peff.net
In-Reply-To: <87si34hphr.fsf@igel.home>

```
On Mon, Dec 14, 2015 at 07:08:48PM +0100, Andreas Schwab wrote:

> 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, 2015-12-14 21:17

Subject: Re: git bisect with temporary commits
Message-ID: <xmqqegeoivcg.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqegeoivcg.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20151214210936.GD14788@sigill.intra.peff.net>

```
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)

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, 2015-12-14 21:26

Subject: Re: git bisect with temporary commits
Message-ID: <20151214212636.GG14788@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20151214212636.GG14788%40sigill.intra.peff.net
In-Reply-To: <xmqqegeoivcg.fsf@gitster.mtv.corp.google.com>

```
On Mon, Dec 14, 2015 at 01:17:03PM -0800, Junio C Hamano wrote:

> 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

```
