Is a more targeted recovery from git bisect mistakes possible?
Asked Answered
B

1

7

I am aware that it is possible to fix a git bisect session via git bisect log and git bisect replay as described in the answers to this question.

However, when I mess up a bisect session, that's likely just a single wrong decision, and I would like to be able to fix it directly (i.e. without aborting the whole thing).

For instance, I can imagine that it should be possible to just do rm .git/refs/bisect/good-<hash> to undo an erroneous git bisect good.

Is this correct, or have I missed something?
And, can an analogous manipulation be done for an erroneous git bisect bad?

Biogeochemistry answered 28/5, 2015 at 12:28 Comment(2)
git bisect is a shell script, go for it.Endogamy
@Endogamy Ah, cool, I didn't realize it was that easy, only roughly 500 LOC :-) I'll definitely take a closer look at that script.Biogeochemistry
B
6

Yes, those refs are what git bisect uses to know its current state. As such, it is possible to undo an erroneous git bisect good by adjusting the refs using git update-ref.

However, this has two catches:

  1. Good and bad commits are marked differently by git bisect:

    • All commits that are marked as good get a refs/bisect/good-<commit id> ref. As such, this can be undone with a corresponding

      git update-ref -d refs/bisect/good-<commit id>
      
    • However, git bisect only keeps track of a single bad commit, so you are required to reset the ref refs/bisect/bad to a known bad commit with

      git update-ref refs/bisect/bad <really bad commit id>
      

      You will likely need to take a look at the bisect log (under .git/BISECT_LOG or via git bisect log) to find out to which commit to reset the refs/bisect/bad ref.

  2. In addition to the refs, git bisect keeps track of all its actions in a log located at .git/BISECT_LOG. While this log is irrelevant for normal operation, fiddling with the refs yourself will lead to a nonsensical log. Of course, you may either ignore that or fix the log accordingly, but that would not be better than the solution that you have linked.

So, yes, this can be done, but there is a price to pay. All in all, saving the log, fixing it, and replaying it seems to be the better alternative.

Biogeochemistry answered 20/6, 2015 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.