After a power loss during a commit, one of the branches in my git repository got corrupted. I did git fsck --full
and deleted all the empty object files until fsck
gave me:
Checking object directories: 100% (256/256), done.
Checking objects: 100% (894584/894584), done.
error: refs/heads/git-annex does not point to a valid object!
Checking connectivity: 862549, done.
I then used git fsck --lost-found
to find my last good dangling commit on the git-annex
branch. I checked it out.
I want this to be my replacement git-annex
HEAD. I tried git checkout -b git-annex
but got that the branch already exists. So I tried git branch -d git-annex
but got error: Couldn't look up commit object for 'refs/heads/git-annex'
.
How can I get rid of the broken git-annex
branch in order to set it to the commit I want? I have already tried just removing .git/refs/heads/git-annex
but that doesn't work. Thanks.
This works for me (after "cheating" to insert a broken branch, and seeing the same error when trying to delete it):
git branch -f broked HEAD # or some other valid point
git branch -d broked
The second command gripes as it deletes the broken ref from .git/packed-refs (which is where I assume it must be if removing .git/refs/heads/git-annex was unhelpful). (But the branch name "git-annex" makes me wonder if you're using git-annex, as in, the thing that stores large files outside the repo. I have not used that myself and am not sure if this changes anything.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With