Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a more targeted recovery from git bisect mistakes possible?

Tags:

git

git-bisect

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?

like image 893
cmaster - reinstate monica Avatar asked May 28 '15 12:05

cmaster - reinstate monica


People also ask

How do I remove a bad commit in git bisect?

Use git log to check the previous commits. Use Git Bisect to find the commit in which line 2 is changed from 'b = 20' to 'b = 0.00000'. Remove the bad commit by using Git Revert. Leave the commit message as is.

What is the use of git bisect?

The git bisect command is used to discover the commit that has introduced a bug in the code. It helps track down the commit where the code works and the commit where it does not, hence, tracking down the commit that introduced the bug into the code.

What is git bisect how can you use it to determine the source of a regression bug?

The git bisect command is a fantastic tool that can help you determine which commit introduced the bug. A regression bug is a specific type of software bug that prevents a feature or software from working when it was working before the bug was introduced. Just remember, git bisect won't "fix" the broken commit for you.


1 Answers

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.

like image 111
cmaster - reinstate monica Avatar answered Oct 17 '22 20:10

cmaster - reinstate monica