Reputation: 266
I just got an error after a recent commit using Tortoise Git:
"Could not get all refs. libgit2 returned: corrupted loose reference file"
which pops up when I go to check the Log.
Any ideas on how to rectify this?
Upvotes: 23
Views: 23147
Reputation: 4598
I had this problem after a hard reboot of my windows 10 machine in my local repo. The mentioned file (in the error dialog) contained only some 0x00 bytes where the other files in that folder contained a hash.
I just deleted that file, and the tortoise git log could open without error again.
Upvotes: 1
Reputation: 1760
I had the exact same error and managed to get my repo back without losing my changes.
I:
And my repository was back working ...
To make sure I did not push anything wrong, I cloned again from the remote, checked-out the changes I wanted to save from the restored repository, and comited them fresh.
Upvotes: 0
Reputation: 1370
In my case it was the use of "junction tool" (sysinternals). Got that error only when adding new sub directory and files. Using git bash the problem does not occur. Everything else works fine with "junction tool" and TortoiseGit ...
Upvotes: 1
Reputation: 2606
Your refs are stored inside the raw repository (in .git) in directories (named for each branch) under the "refs" directory. The problem is that one of these files has been corrupted. If you check the code here you'll see that the problem is either that the ref file is less than 40 bytes long, or has a 41st byte that is not a space (or tab, newline, etc). Search through the files in the .git/refs directory and you'll find the bad one. It should contain the 40-character hash of the commit which that branch refers to. You can safely fix it using Notepad.
Upvotes: 24