fatal: could not parse HEAD Error When Committing

19,412

Solution 1

Do you know what branch HEAD was supposed to point to? Was it master? Run git symbolic-ref HEAD refs/heads/master.

Basically, the symbolic reference with the name HEAD is corrupted somehow. You (or software you ran) must have gone poking around the .git dir. If I were you I would check to make sure nothing else in your repo is damaged. You can verify your object database by running git fsck.

Solution 2

Copy the new files you recently changed to another directory, delete the git local repository in your computer, clone the repository again using 'git clone URL', move the recently changed files your copied to another back to this directory, do git add files, git commit -m " ur msg ", and push to the remote repository using git push

Share:
19,412
MichaelScaria
Author by

MichaelScaria

I develop software.

Updated on June 07, 2022

Comments

  • MichaelScaria
    MichaelScaria almost 2 years

    Whenever I try to commit my work, I get this error.

    fatal: could not parse HEAD
    

    What should I do if I want to preserve my changes?

  • MichaelScaria
    MichaelScaria over 11 years
    I think you are right I ran git fsck and got this: notice: HEAD points to an unborn branch (trunk)
  • Lily Ballard
    Lily Ballard over 11 years
    @MichaelScaria: Well that's actually my fault. I said trunk instead of master, because I've been using git-svn too much lately. Try again with git symbolic-ref HEAD refs/heads/master. I'll update my post appropriately
  • MichaelScaria
    MichaelScaria over 5 years
    It seems like you didn’t initialize git properly in your folder. Did you remember running git init?
  • Nodira
    Nodira over 5 years
    Yes you are right. I forgot to git init. But, when I remembered I had have already been working for long hours and couldn't loose those changes.
  • Camunatas
    Camunatas over 2 years
    this is the easiest and most robust solution