git 致命:提交时无法解析 HEAD 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14449372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fatal: could not parse HEAD Error When Committing
提问by MichaelScaria
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?
如果我想保留我的更改,我应该怎么做?
回答by Lily Ballard
Do you know what branch HEAD
was supposed to point to? Was it master
? Run git symbolic-ref HEAD refs/heads/master
.
你知道HEAD
应该指向哪个分支吗?是master
吗?运行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
.
基本上,带有名称的符号引用以HEAD
某种方式损坏了。您(或您运行的软件)一定已经在.git
目录中闲逛了。如果我是你,我会检查以确保你的仓库中没有其他东西被损坏。您可以通过运行来验证您的对象数据库git fsck
。
回答by uche Godfrey
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
将最近更改的新文件复制到另一个目录,删除计算机中的 git 本地存储库,使用“git clone URL”再次克隆存储库,将复制的最近更改的文件移回另一个目录,执行 git add files, git commit -m " ur msg ",然后使用 git push 推送到远程仓库
回答by Nodirabegimxonoyim
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:
我刚才有同样的问题。我的项目中的另一个存储库发生了变化git changes field
。我尝试取消暂存它们,并且只推送有关我想要的文件夹的更改。到目前为止,我努力克服更改其他文件夹的问题(使用 .git 等从 pc 中删除项目文件夹)。我不确定我是否可以解释这种情况,但以下是帮助我的原因:
I copied the .git
file which I removedwith project folders from recyle bin. Copied the fileand pasted in the folderof 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.
我复制了.git
我从回收站中与项目文件夹一起删除的文件。复制文件并粘贴到我在提交时遇到 HEAD 问题的项目文件夹中。我看到有零件丢失。它复制.git
文件夹中与当前不匹配的所有部分,并显示消息以跳过或保留已存在的部分。我只是跳过了它们。它对我有用。我希望这会在将来对其他人有所帮助。