How to get rid of "refs/bisect/bad" branches in Git
Asked Answered
A

2

11

I have the following in my ~/.gitconfig (this is only here to help you understand what I'm looking at):

[alias]
    lg = log --graph --all --pretty=format:'%Cred%h %Cgreen(%cr)%Creset - %s %C(yellow)%d %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

When I do a git log, it shows me the full commit tree with branch names and stuff. Yesterday I initiated a git bisect and today I see there is a refs/bisect/bad branch in the output of my log.

What exactly is the refs/bisect/bad branch and how do I get rid of it?

Aegir answered 11/3, 2011 at 10:34 Comment(0)
E
12

When you're using git bisect, it uses refs/bisect/bad to track the last bad commit. (That ref is updated when you do git bisect bad.)

I suspect that what's happened here is that you got to the end of the bisect, and it reported the first bad commit, but you never ended the bisection with git bisect reset, which would clean up the refs that it created. You can still run that command, and it'll take you back to where you were before starting the bisections - however, I'd make sure that your work is committed and git status is clean before doing so, just to avoid any possible confusion.

If you use __git_ps1 in your bash prompt, it will helpfully note that you're still in a bisection by outputting (9dad0bb...)|BISECTING. I discussed __git_ps1 a bit in another answer, which might be helpful.

Envy answered 11/3, 2011 at 10:48 Comment(1)
In relatively recent versions of Git, you can also use git bisect reset HEAD to avoid switching commits.Comnenus
I
13

That's a pointer for commit marked as bad during bisect. You can run

git bisect reset

or manually remove the pointer from .git/refs/bisect (but I don't recommend that)

Interferometer answered 11/3, 2011 at 10:47 Comment(0)
E
12

When you're using git bisect, it uses refs/bisect/bad to track the last bad commit. (That ref is updated when you do git bisect bad.)

I suspect that what's happened here is that you got to the end of the bisect, and it reported the first bad commit, but you never ended the bisection with git bisect reset, which would clean up the refs that it created. You can still run that command, and it'll take you back to where you were before starting the bisections - however, I'd make sure that your work is committed and git status is clean before doing so, just to avoid any possible confusion.

If you use __git_ps1 in your bash prompt, it will helpfully note that you're still in a bisection by outputting (9dad0bb...)|BISECTING. I discussed __git_ps1 a bit in another answer, which might be helpful.

Envy answered 11/3, 2011 at 10:48 Comment(1)
In relatively recent versions of Git, you can also use git bisect reset HEAD to avoid switching commits.Comnenus

© 2022 - 2024 — McMap. All rights reserved.