How to remove "fatal: loose object"?

Viewed 42635

One of my cloned repositories is getting this from a git fsck

fatal: loose object 40bda4e3b79c3d7bf598df31d9e68470f97a3f79 (stored in .git/objects/40/bda4e3b79c3d7bf598df31d9e68470f97a3f79) is corrupt

I've got another copy of it that fsck's cleanly.

I've tried nuking the directory/subdirectories that contain the fatal one, and recloning it. The problem continues.

I really don't care about any particular file, I just want the repository to checkout cleanly. What do I do?

Note: the remote repository is hosted on github.

7 Answers

I faced this issue and this simple trick solved the issue.

Step 1

Suppose you are facing this issue in a folder named "my-project" with branch "my-new-feature", clone the repo to a new folder named "my-project-dummy" and checkout to "my-new-feature"

Step 2

Delete ".git" folder in "my-project" folder and copy ".git" folder from "my-project-dummy" folder to "my-project"

Tadaaa you are good to go now.

you should recreate a repo:

  • delete .git folder
  • copy everything from working directory to backup directory
  • git init
  • git remote add origin https://github.com/USERNAME/REPONAME.git
  • git pull
  • git checkout -b backup
  • git add .
  • git commit -m "add backup"
  • git checkout master
  • you are back to go (master branch)
Related