Recreate Git Ref after Fatal Error

眉间皱痕 提交于 2019-12-31 00:55:12

问题


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:


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.



来源:https://stackoverflow.com/questions/9505097/recreate-git-ref-after-fatal-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!