2

When trying to commit with

git commit -a -m "Huge update"

I get

fatal: could not parse HEAD Error When Committing

After reading fatal: could not parse HEAD Error When Committing I commanded

 git symbolic-ref HEAD refs/heads/master

but got no output, but I did get

$ git fsck
Checking object directories: 100% (256/256), done.
error: HEAD: invalid sha1 pointer c45fd8579e1f313fcd651df4cbafbf6c8f8edba6
error: refs/heads/master does not point to a valid object!
error: refs/remotes/origin/master does not point to a valid object!
notice: No default references
broken link from  commit f10ca5f9234acb473ee000414e2c7d4e939b5e57
              to    tree 08a537c82c15e09badb41540ceadfb6ac1a8bb31
dangling blob 03165e2de43b743cfe049c40d0ede67fcfb3cc50
missing tree 08a537c82c15e09badb41540ceadfb6ac1a8bb31
dangling blob 1d5469bbebc0a347feef8c0d04fdbf54d87c0a84
dangling blob 1d29ed6cbea9e49273f072de1c61d6893c60a938
dangling blob 259577cbf5a72f6a3565fabb8ce84dc1c7953263
missing blob 3e2a6250392ee3148da37c6c140fc27302125efd
dangling blob 5474b368e2be10dc252d9e21942e748b2d87bd8c
dangling blob 743f1a142592da8050327a6d2e8acc9b5caface7
dangling blob 74823e581bb2cd05256fb4c53109ab6690164077
dangling blob 8399f1b02b73271337addc62e1cc0655a3437a9e
missing blob 99e63739e12ac210f709cc7d5426b46c6b869b65
dangling blob ba11541ed0813e1310b0d721c558f77197854f1f
dangling blob bab5ebd6dfda1be835d15c7704e192e6a9372404
missing blob ca265d70b113843c3080fcb29e14ddb7c50c55a2
missing commit d5750c2c0c209f95d1d6bbd8f763756302fa31b9
dangling blob ebfe8060c0c12ec4b9c7ebebcedbf6c33f435a32
dangling blob f16d2a532c3720bbeb14334a47dc5835532d9841

I might be mistaken, but think git told me to go and f*** myself :-D... :,-/. The following seems to confirm this:

$ git status
fatal: bad object HEAD
$ git checkout master
fatal: Reference is no "Tree"-object: master
$ git fetch
error: refs/heads/master does not point to a valid object!
error: refs/remotes/origin/master does not point to a valid object!
$ git reflog master
fatal: bad object master
$ git reflog HEAD
fatal: bad object HEAD

Is there still a way to reconcile with git?

I also get

$ cat .git/refs/heads/master
c45fd8579e1f313fcd651df4cbafbf6c8f8edba6
$ cat .git/refs/remotes/origin/master
c45fd8579e1f313fcd651df4cbafbf6c8f8edba6
Make42
  • 12,236
  • 24
  • 79
  • 155
  • What is your ideal final outcome? I take it you have some local changes that you want to commit. What branch do you want to commit them on? Do you currently have that branch checked out? If not, can you do `git checkout branch-name` and then commit? – Code-Apprentice Apr 02 '18 at 20:17
  • Can you please post the rights and the content of your HEAD file : `ls -l .git/HEAD ; cat .git/HEAD` ? – LeGEC Apr 02 '18 at 20:25
  • @Code-Apprentice: Yes, I want to commit local changes. I only have a master branch. As you can see in the question, checking it out did not work. – Make42 Apr 02 '18 at 20:27
  • @LeGEC: I got: -rw-rw-r-- 1 me me 23 Apr 2 22:07 .git/HEAD ref: refs/heads/master – Make42 Apr 02 '18 at 20:28
  • @Make42 : ok; can you check that `cat .git/refs/heads/master` gives you the same sha1 as the invalid sha1 mentionned by your `git fsck` ? – LeGEC Apr 02 '18 at 20:34
  • @Make42 : same check on `.git/refs/remotes/origin/master` – LeGEC Apr 02 '18 at 20:38
  • @LeGEC: Please see my updated question. – Make42 Apr 03 '18 at 07:38
  • Did anything special happen on your pc that might have caused the corruption inside the git repository, like a blue screen? – Ferrybig Apr 03 '18 at 07:50
  • @Ferrybig: Nothing that I am aware of. However, I did not use git on this repo for about a year. I worked on the files, but never committed, pushed or pulled from the server. So I do not know whether something happened during this year, that I do not remember. – Make42 Apr 03 '18 at 10:35
  • Hi @Make42, were you able to return to a stable repo while keeping your changes ? – LeGEC Apr 06 '18 at 09:12
  • @LeGEC: Yes, what I did was, cloned the repo from the server and moved my changes manually to the new repo and deleted the old one. I think I did not loose anything. So everything is good, but a little frustrating that it wasn't possible to actually fix, but hey, all's well that ends well. I just noticed the update in your answer - am gonna check it out. – Make42 Apr 06 '18 at 16:21

4 Answers4

6

It looks like something bad happened to your local repo.

See if a simple git fetch helps you get back some of these missing objects.


Can you create a fresh clone of the remote repository, and check :

  • if refs/remotes/origin/master still points to c45fd85..., or or if it has c45fd85... in its history ?
  • if c45fd85... exists and is a valid object ? (git fsck, git cat-file -p c45fd85)
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • In fact: In the newly cloned repo, I can see that `c45fd85...` had been the commit before my new commits. The commit seems to be valid here. – Make42 Apr 06 '18 at 16:24
  • ok, and in the fawlty repo, does `git cat-file -p c45fd85` show you something ? – LeGEC Apr 06 '18 at 16:26
  • I deleted the faulty repo by now, so we won't know. Sorry. – Make42 Apr 06 '18 at 17:07
2

I have the same problem I read every answer here nothing helped. But, when I deleted the ".git" folder in my project directory and re-initialized the problem is gone. I hope this helps you too.

SaboSuke
  • 634
  • 6
  • 21
1

The refs/heads/master file is a reference that's supposed to point to a valid commit hash. For some reason, your master points to c45fd8579e1f313fcd651df4cbafbf6c8f8edba6 which doesn't exist in your repository. It could be that this object was deleted from the .git/objects directory somehow or it could be that master points to a hash that never existed. I can't be sure till I know what all you did. It's possible that a git reflog master or git reflog HEAD will offer some clues as to what happened but I can't be sure.

My guess is that your .git directory was tampered with. I see several missing commits. That's a not a good sign. If you have the repository pushed safely to some location, cloning again is one way to fix the problem. If the reflog commands gives you useful output, you can forcefully reset (git reset --hard) your master to the previous commit it was on (git reset --hard master@{1}) and then try fetching again. Hopefully, it will bring in all the missing commits. This will destroy the latest commit but given that it's dangling anyway, I don't think you stand to lose much.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
1

I arrived here after deleting the empty objects as mentioned here:

How can I fix the Git error "object file ... is empty"?

After removing the empty objects things went worse. At the end, I solved it by doing:

git reset --hard origin/master
kendallbp
  • 61
  • 5