2

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?

Fabio Manniti
  • 151
  • 12
  • 1
    It might be that the `.git` folder is higher up? – evolutionxbox Jun 28 '22 at 09:12
  • 1
    I must admit that this was my concern even if I used to do this all the time. But if I do on the highest level git status I get "not a git repository (or any of the parent directories): .git" – Fabio Manniti Jun 28 '22 at 09:35
  • @evolutionxbox I am also trying to do "locate .git" but I get "No such file or directory". It looks like it doesn't exists at all – Fabio Manniti Jun 28 '22 at 09:56
  • "Higher up" does not mean "highest up". Find the .git folder. For example, type `git rev-parse --git-dir`. – j6t Jun 28 '22 at 09:56
  • `locate` uses a fast-lookup database; this database is generally built nightly or weekly, or not at all, so it may not have the necessary information. – torek Jun 28 '22 at 09:57
  • @j6t Thanks, I didn't know that command. Unfortunately I got this response fatal: not a git repository (or any of the parent directories): .git – Fabio Manniti Jun 28 '22 at 10:00
  • Run the command in the directory where you also see the original error. – j6t Jun 28 '22 at 10:11

2 Answers2

1

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.

lior.i
  • 573
  • 1
  • 7
  • 20
  • 1
    Glad it solved things for you, but this 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. That works only if you *have* a remote copy that has everything that you had locally. – j6t Jun 28 '22 at 14:39
  • Thanks for the comment @j6t, I agree with you that this solution is a bit aggressive, but for me, it was better than the alternative which was to clone a copy of the repo and copy the uncommited source files to it. – lior.i Jun 28 '22 at 14:46
0

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?).

torek
  • 448,244
  • 59
  • 642
  • 775
  • Among these three options I would say number 2 because it is a virtual machine and, for what I know, there is no antivirus software and no Dropbox or "similia" because there is no need. There is just a bunch of files used to work. But I don't know what should I do – Fabio Manniti Jun 28 '22 at 10:15
  • Could be—or it could be some shared file system that your virtual machine is using. I have had a drive fail on me on a Linux box, and it caused interesting problems, which took a while to figure out that it was a bad disk drive. – torek Jun 28 '22 at 10:29