Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fatal: bad object HEAD

Tags:

git

Can somebody help me to solve this problem. I had made a previous post about this but I couldn't solve it through those answers. Please help:)

I have tried to run git fsck --full and I get :

Checking object directories: 100% (256/256), done.
error: HEAD: invalid sha1 pointer 15044de63184bed22f9be9f48fd63a3a7652eea4
error: refs/heads/master does not point to a valid object!
notice: No default references
dangling blob f4ffb48ece75b45ec593146216a2ecae5a5b2194
dangling blob f37ffd41d80a2d07258d0b8fa7118d236d480fc0
dangling blob f1ff1fa538a538d9085e573f60ad11e8e7f5395e
dangling blob f9ff6bdaf08fdbf9001ff44d2aa1a49092c20ad1
dangling blob f97f1a223ef3ca33f55d51ae25d98d3b5b2f9ece
like image 271
H Abdi Avatar asked Sep 11 '14 21:09

H Abdi


3 Answers

In my case, I edited .git/refs/remotes/origin/HEAD. I couldn't get git update-ref to work, but that seems to be the recommended way.

So if git checkout (<branch> | <commit>) doesn't work, you should try something like git update-ref HEAD ref:master or just try editing .git/HEAD.

like image 121
Jayen Avatar answered Nov 07 '22 14:11

Jayen


I had the same problem. Simply doing a git pull origin master fixed it, and left my local edits intact.

like image 15
henrikstroem Avatar answered Nov 07 '22 12:11

henrikstroem


"invalid sha1 pointer" in combination of git gc was seen before (git for windows issue 423)

git 2.7 (Q4 2015) will fix this:

See commit 14886b4, commit 8c845cd (28 Sep 2015) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit 1018f3e, 15 Oct 2015)

"git gc" used to barf when a symbolic ref has gone dangling (e.g. the branch that used to be your upstream's default when you cloned from it is now gone, and you did "fetch --prune").

More precisely:

pack-objects: do not get distracted by broken symrefs

It is quite possible for, say, a remote HEAD to become broken, e.g. when the default branch was renamed.

We should still be able to pack our objects when such a thing happens; simply ignore broken symrefs (because they cannot matter for the packing process anyway).

like image 3
VonC Avatar answered Nov 07 '22 12:11

VonC