Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git log: fatal object [sha1] is corrupted

Tags:

git

Is there any way I can repair my repository with commit history in tact.

 # git log
fatal: object 01aeb2bf2e93b238f0e0422816b3e55518321ae7 is corrupted

From reading the link below it looks like I'll have zap it and start over.

http://www.miek.nl/s/7e76eadefe/

like image 571
Keyo Avatar asked May 25 '10 23:05

Keyo


5 Answers

Do you have clones of this repository elsewhere? You might want to read this post by Linus Torvalds to restore that corrupted object, assuming the corrupted object is a blob (file contents).

like image 105
Bram Schoenmakers Avatar answered Oct 27 '22 17:10

Bram Schoenmakers


I wound up in the same situation, probably due to an improper shutdown of the virtual machine I was working in. There were approximately 10 objects in .git/objects that had zero length. As far as I can tell, the actual source code files were fine, just the repository was hosed.

$ git status
fatal: object fbcf234634ee04f8406cfd250ce5ab8012f92b08 is corrupted

Per some suggestions I saw elsewhere (including Linus's post referenced above), I tried temporarily moving the corrupted objects git was complaining about from .git/objects elsewhere. When had moved all of them, I got:

$ git status
fatal: bad object HEAD

After about an hour of Googling and trying various solutions, I gave up and started a new working copy using 'git clone' to pull from the origin (which was about 2 hours behind my working copy). I then used rsync -rC (-C excludes SCM files) to copy the changed files from the messed-up working copy to my new working copy.

like image 42
Jase Avatar answered Oct 27 '22 16:10

Jase


You could also try to restore these objects by merely copying them from other repositories.

My virtual machine crashed while recording a pushed commit, so the objects were safely stored on a local computer. I scp'ed them to virtual machine and voila — git fsck outputs no errors.

like image 1
Denis Gorbachev Avatar answered Oct 27 '22 16:10

Denis Gorbachev


Simply delete the corrupt object that git is complaining about. I was able to resolve the same issue just now this way.

fatal: object 985a4870e7d890b314d2794377045a8b007c7925 is corrupted

For the above error, I was able to find corresponding object at:

project_directory/.git/objects/98/5a4870e7d890b314d2794377045a8b007c7925

Where you can see the file is 0 bytes and deleting it allowed the fetch to start working.

Presumably the previous fetch was interrupted, leaving the corrupt object with size = 0 bytes.

like image 1
Anson Kao Avatar answered Oct 27 '22 17:10

Anson Kao


Had the same problem, whichever git command I ran, It ended up with the message:

fatal: object <hash> is corrupted

I didn't have a backup and didn't want to lose my commits, so I decided to try Jase's solution and removed the 0 length file I had : .git/objects/00/<hash> Then got the same:

$ git status
fatal: bad object HEAD

Then, I tried to know what was wrong and looked into .git/refs/heads/masterwhere I had the hash.

I looked into .git/logs/refs/head/masterand found lines like this one:

<old commit> <new commit> <author> <timestamp> commit: <commit message>

I removed the last line (which had =) and pasted of this line into .git/refs/heads/master, erasing its content

I was then able to commit successfully.

like image 1
cube45 Avatar answered Oct 27 '22 17:10

cube45