John Mattucci
John Mattucci

Reputation: 266

TortoiseGit Error - Could not get all refs. libgit2 returned: corrupted loose reference file

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

Answers (4)

Heri
Heri

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

Milan
Milan

Reputation: 1760

I had the exact same error and managed to get my repo back without losing my changes.

I:

  • Made several backups of the corrupt git repository just in case
  • Cloned the lasted pushed version from the remote repository
  • Copied all the files from the corrupt .git folder EXCEPT all files related to HEAD, FETCH_HEAD, ORG_HEAD etc ... the most important are the refs, obj, and index
  • Ended up with a valid history, but corrupt index, applied the solution from this post How to resolve "Error: bad index – Fatal: index file corrupt" when using Git

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

hfrmobile
hfrmobile

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

cliffordheath
cliffordheath

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

Related Questions