4

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.

Community
  • 1
  • 1
ServAce85
  • 1,602
  • 2
  • 23
  • 51
  • what happens if you run 'git log ' ? Maybe you can get the SHA of the commit before the rebase, and checkout that – carpii Mar 02 '12 at 04:30
  • Also try git reflog, and see if you can checkout (or reset) to the commit before the rebase that way. Before trying either of these, Id really take a full copy of your repo somewhere safe – carpii Mar 02 '12 at 04:32
  • Copied... Now I've tried `git log branchName` and it gives me the first error (the one referring to the `ebca16` SHA. I tried `git reflog` and again, I receive that same error. – ServAce85 Mar 02 '12 at 04:55
  • Why don't you restore the repository from your backup? – hakre Mar 10 '12 at 23:44

1 Answers1

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.

ServAce85
  • 1,602
  • 2
  • 23
  • 51