fatal: could not parse HEAD Error When Committing

大憨熊 提交于 2019-12-10 02:17:28

问题


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?


回答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.




回答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




回答3:


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.



来源:https://stackoverflow.com/questions/14449372/fatal-could-not-parse-head-error-when-committing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!