MichaelScaria
MichaelScaria

Reputation: 1590

fatal: could not parse HEAD Error When Committing

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?

Upvotes: 18

Views: 29786

Answers (3)

Nodira
Nodira

Reputation: 666

I had the same issue just now. There were changes from another repositories in my project git changes field. I tried to unstage them, and pushed only changes regarding the folder I want. So far, I struggled a bit for overcoming the problem with changes of other folders (deleted project folder from pc with .git, etc.). I am not sure whether I could explain the situation, but here is what helped me:

I copied the .git file which I removed with project folders from recyle bin. Copied the file and pasted in the folder of the project which I faced the problem with HEAD in commit. I saw that there were parts missing. It copied all parts that didn't match with current .git in the folder and showed message to skip or keep for those that already exist. I just skipped them. It worked for me. I hope this will help someone else in the future.

Upvotes: -1

uche Godfrey
uche Godfrey

Reputation: 121

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

Upvotes: 5

Lily Ballard
Lily Ballard

Reputation: 185681

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.

Upvotes: 11

Related Questions