Recreate Git Ref after Fatal Error

2019-02-24 05:19发布

I recently had to perform a hard reboot and I am now receiving an error in git when I try to access a specific branch (this does not happen when accessing other branches):

$git checkout branchName
fatal: failed to read object ebca165c3ec7ecd7124f41983dd264e4e1dc0125: Invalid argument

The problem is similar to the one described here: How to restore a corrupted git repository?, but differs in the fact that I am not currently on that branch to perform git status. Also, if I call git reflog I receive the same error message.

I tried to delete the branch in question using git branch -d branchName and git branch -D branchName, but have had no success.

Obviously, I would love to keep all of the branches and data, but if the solution is to delete that specific branch, then that is fine. Also, don't know if this helps or even matters, but the last action performed on this branch was rebase.

Would a possible solution be to reconstruct the current ref from each of the individual branches that exist, excluding the invalid branch?

As a side note, I don't have a remote source that I'm comfortable cloneing from at this point, so any local solutions are desired. Also, I'm using PHP in case that matters for any reason.

Thanks.


Edit:

Running git fsck --full I receive the following message:

$git fsck --full
fatal: failed to read object 687f624bd239de165307d18a8904a77adb32c8a1: Invalid argument

...which is odd because it seems to refer to a different hash.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-02-24 06:12

I finally found out how to answer this question...

Simply go into the folder .git and delete refs/heads/BadBranch

This allows the rest of the branches to work as they normally should, while only losing information from the corrupted branch.

查看更多
登录 后发表回答