15

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
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
H Abdi
  • 151
  • 1
  • 1
  • 3
  • maybe this post will help? http://stackoverflow.com/questions/17274575/git-refs-heads-master-does-not-point-to-a-valid-object – AgileDan Sep 11 '14 at 21:57
  • You should be able to just `git checkout master` (or any other branch name) to get a valid HEAD ref for your working copy. – Barend Sep 11 '14 at 21:57
  • I have tried it I get this fatal: reference is not a tree: master – H Abdi Sep 11 '14 at 22:01
  • Also, have you tried `git gc` ? – AgileDan Sep 11 '14 at 22:02
  • yep I get this: error: refs/heads/master does not point to a valid object! error: refs/heads/master does not point to a valid object! fatal: bad object HEAD error: failed to run repack – H Abdi Sep 11 '14 at 22:02
  • your repository may be corrupted. check out this thread: http://stackoverflow.com/questions/18678853/how-to-fix-corrupted-git-repository – AgileDan Sep 11 '14 at 22:04
  • Thanks I appreciate your help. do you have 2 more minutes to show me how i should implement the solution shown on the link? – H Abdi Sep 11 '14 at 22:09
  • 10
    TWO OF THE SUGGESTIONS ABOVE ARE DEFINITELY BAD IDEAS IF YOU HAVEN'T BACKED EVERYTHING UP. `git gc` is not likely to fix anything, however it cleans up anything that Git thinks it might be finished with. This makes it much less likely that you will be able to reverse recent changes or find lost versions of files which you care about. `git checkout master` will replace your file tree with `master` branch. However, if you have the above problem your recent commits may have been lost. Checking out master means that your only record of your local branch changes (the files themselves) is destroyed. – jwg Jun 16 '15 at 14:08
  • I had a similar issue when updating from git 2.5.0 to 2.5.3. See https://github.com/git-for-windows/git/issues/423. – koppor Sep 21 '15 at 19:46
  • That error should disappear with git 2.7 (Q4 2015). See [my answer below](http://stackoverflow.com/a/33165817/6309) – VonC Oct 16 '15 at 08:30

4 Answers4

20

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.

Jayen
  • 5,653
  • 2
  • 44
  • 65
15

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

henrikstroem
  • 2,978
  • 4
  • 35
  • 51
3

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-7

I had the same problem that appened to me because of some problems with git objects. The only way to fix them is to do a git clone in a different folder and then copy-paste all in the old folder.

I will lee you know if i will find a different solution.

Regards

Marcus
  • 80
  • 6
  • 3
    This might be *a* way to fix them, but it certainly isn't the only way. – jwg Jun 16 '15 at 14:04
  • I managed to fix a similar problem without doing git clone and starting again, which meant that I kept my branches and commits. See my answer http://stackoverflow.com/a/30872027/1737957 – jwg Jun 16 '15 at 22:39