Home > Software engineering >  git: object file is empty when git status or git pull
git: object file is empty when git status or git pull

Time:06-29

I hope someone can help me.

Last week everything was ok, then yesterday I don't know what happened.

(My OS is Fedora).

I am in the directory where I have my project /app/app and I was trying to do a git status or a git pull but I get this response:

error: object file .git/objects/43/5d56e948bdc05f6c0fdcc8851bcc2559524f0a is empty
error: object file .git/objects/43/5d56e948bdc05f6c0fdcc8851bcc2559524f0a is empty
fatal: loose object 435d56e948bdc05f6c0fdcc8851bcc2559524f0a (stored in .git/objects/43/5d56e948bdc05f6c0fdcc8851bcc2559524f0a) is corrupt

I tried following this link but when I do

cp -a .git .git-old

I get

cp: cannot stat '.git': No such file or directory

So it looks like I don't have git. I removed and reinstalled it:

yum remove git
yum clean all
yum install git

but when I did git status I still got the same problem.

Does anyone has a better idea?

CodePudding user response:

This:

fatal: loose object 435d56e948bdc05f6c0fdcc8851bcc2559524f0a (stored in
    .git/objects/43/5d56e948bdc05f6c0fdcc8851bcc2559524f0a) is corrupt

indicates that you do have Git installed, but your repository is in some location on your computer such that it is being actively damaged by something.

That "something" could be:

  • (extremely-)badly behaved antivirus software
  • a failing disk drive
  • network-syncing software such as OneDrive or Dropbox or similar

(this is not meant to be a complete list of possibilities, just some of the common ones—there are many ways that Linux systems allow you to shoot yourself in the foot, and Git can't stop most of them).

You should find out what's damaging your files and fix that (e.g., move your repository away from network syncers). In this particular case, it seems likely that something was going about removing files and directories (perhaps a nightly cleanup?).

CodePudding user response:

As people before me said if you have the .git/objects scenario you have git installed in your machine, maybe you deleted the .git directory by mistake.

I'm having this problem every once in a while, I'm working with VirtualBox VM on Windows and it's happening due to computer or VM operation problems.

The best solution for me is to remove the git objects and all related ref git files:

sudo rm -r .git/objects/* .git/refs/heads/* .git/refs/remotes/* .git/refs/stash .git/refs/tags/*

and then pull the repo:

git pull

That solves everything for me in the easiest way without risking my source code or cloning the repo again.

###Edit###

As @j6t commented, my solution is a bit aggressive:

The solution is not suitable for users who don't know what they are doing. You basically blow away the Git database, and then you fill it in with a remote copy.

I couldn't agree more, my solution is an alternative to the simple solution of cloning a copy of the repo (without empty object files) and then copying the uncommitted source files to it, which blows away the Git database and then fill it in with a remote copy as well.

  •  Tags:  
  • git
  • Related