Reputation: 2404
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.
Upvotes: 28
Views: 46660
Reputation: 1
The idea is:
rm -rf .git
git init
.git remote add origin urlOfUrReposotiry
urlOfUrReposotirygit fetch
.git checkout -b master origin/master -f
.That's it!
Upvotes: 0
Reputation: 8560
you should recreate a repo:
Upvotes: 0
Reputation: 5728
I faced this issue and this simple trick solved the issue.
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"
Delete ".git" folder in "my-project" folder and copy ".git" folder from "my-project-dummy" folder to "my-project"
Upvotes: 7
Reputation: 2363
The idea is:
.git
under your current project (let's denote it by "project A").cd
into project A and git clone and reset to the last commit.cd
into project A and use git status
to see the status of project A. It should be just as if there was no corruption happened ever.In short, make a copy to reserve your current working area, and merge it with a fresh clone by replacing files and then deal with your changes as normal.
Here's it in action:
First I see I have a corruption (which is because I forced my virtual machine to shutdown inproperly yesterday :P):
✘ domicor@ubuntu ~/dotfiles master ● git status error: object file .git/objects/cd/593f6db1d5050406e15b9c80d215fd48db39f4 is empty error: object file .git/objects/cd/593f6db1d5050406e15b9c80d215fd48db39f4 is empty fatal: loose object cd593f6db1d5050406e15b9c80d215fd48db39f4 (stored in .git/objects/cd/593f6db1d5050406e15b9c80d215fd48db39f4) is corrupt
Make a copy of my dotfiles
folder and now remove the .git
folder.
$ cd ~/dotfiles $ rm -rf .git
Then recreate a git repo.
$ git init
Add a remote.
$ git remote add origin [email protected]:domicor/dotfiles.git
Fetch from the remote.
$ git fetch
Now reset the HEAD.
$ git reset --hard origin/master
Notice that right after I fetched from remote I issued a git status
command to check out the status of my repo. You can see all the files are untracked. And the lst part of the command line prompt is orange from my git init
command to git reset
command indicating that when I initialized my repo, git detected files and after the reset, all files are restored to the state of the HEAD thus the green prompt.
Set the upstream branch:
$ git branch --set-upstream-to=origin/master master
Now copy your files from the backup folder (for me it's dotfiles (copy)
) manually or through the command line to replace files in the dotfiles
folder. Check out the status and there should be changes just like my screen shot:
Now you can git diff your-filename
to check out if your changes are applied properly and you can add files and commit from now on. \o/
To understand it furthur, the git VCS just records your changes. When the VCS is corrupted, your files are still safe. They are still there as you left them. So you backup your files and restore the git records from elsewhere and git can compare the restore copy with your current file status and have ideas about what has changed just as it did before the corruption. And cheers \o/
Upvotes: 7
Reputation: 11
Do git checkout
to the other branch, you will get list of changed files , just commit them and push into the branch.
If you do this the problem will be solved, next time when you do some changes git status
should work.
Upvotes: 0
Reputation: 119
Simplest answer is "rm -rf .git ..." http://www.bazhukov.net/2015/02/git-corrupt-loose-object/
Upvotes: -3
Reputation: 766
First, you can check the file system for errors: fsck -y
Then, check the git repository: git fsck
Upvotes: 4
Reputation: 31451
Easy answer: move the old repo away and reclone. If you have stuff in the old repo you want to preserve, there are ways of getting them, but first get a good repo.
Upvotes: 31