Rob
Rob

Reputation: 7099

cant fix bad object HEAD error with git status

My Battery died on my macbook when pushing my repo. Now I cannot run git status

$ git status
fatal: bad object HEAD
fatal: git status --porcelain failed

I've tried a few suggestions ive found for fixing bad object errors.

$ git fsck --full
dangling tree 65e856976b7aa7c73f15cd71defedb8a3d622a10

I've tried git prune and git prune-packed

I can still commit, stash, push, it appears to be just affecting git status

Andy ideas?

Thanks

Upvotes: 16

Views: 41543

Answers (7)

Michal
Michal

Reputation: 21

I had the same problem and this worked for me:

git fetch origin
git reset --soft origin/master

Upvotes: 1

MakerMax
MakerMax

Reputation: 11

git checkout -f *branchname* worked for me.

Upvotes: 1

Leye Odumuyiwa
Leye Odumuyiwa

Reputation: 674

This worked for me:

git fetch origin
git reset --hard origin/master

Upvotes: 1

philburk
philburk

Reputation: 711

This happened to me when I accidentally added my bin/ folder in an Eclipse Java project.

Using 'git pull' did not work for me.

I fixed it by:

  1. closing Eclipse
  2. rm -rf bin
  3. git rm bin

Then I was able to 'git commit' and continue normally.

Upvotes: 2

dasrecht
dasrecht

Reputation: 450

I guess you solved this problem already but i had this to and could fix it simply by run

git pull

This has resulted into a working condition. eventough your files are intact you should backup your local git directory and then run the git pull. after that you should be back in business.

If there are files deleted (it should not happen) you can copy them back over a working checkout and commit them from there.

Upvotes: 33

joshy
joshy

Reputation: 111

Try add all of your modified files with git add filepath/file.ext before the git status.

Upvotes: 0

wRAR
wRAR

Reputation: 25693

If your .git/HEAD is corrupted or points to a corrupted object, you can change it manually or by git checkout.

Upvotes: 2

Related Questions