Git 无法锁定引用“HEAD”:无法解析引用 HEAD
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39057962/
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
Git cannot lock ref 'HEAD': unable to resolve reference HEAD
提问by Jake Miller
I'm trying to commit the changes to my repository but I receive the error below:
我正在尝试将更改提交到我的存储库,但收到以下错误:
git -c diff.mnemonicprefix=false -c core.quotepath=false commit -q -F C:\Users\Contronym\AppData\Local\Temp\bkdweixb.mnu
fatal: cannot lock ref 'HEAD': unable to resolve reference HEAD: Invalid argument
Completed with errors, see above.
I'm using bitbucket and SourceTree.
我正在使用 bitbucket 和 SourceTree。
What's the reason for this commit failing? I was able to commit just fine the last 3 commits over the past week. Then, all of a sudden, I receive this error.
这次提交失败的原因是什么?在过去的一周里,我能够很好地提交最后 3 次提交。然后,突然间,我收到此错误。
EDIT
编辑
I ran git gc
and these are the results:
我跑git gc
了,结果如下:
$ git gc
error: bad ref for HEAD
error: bad ref for HEAD
error: inflate: data stream error (unknown compression method)
fatal: loose object 53b65bd9b4fec7f6a7b0b3313c68199a18804327 (stored in .git/objects/53/b65bd9b4fec7f6a7b0b3313c68199a18804327) is corrupt
error: failed to run repack
I checked the directory .git/objects/53/b65bd9b4fec7f6a7b0b3313c68199a18804327
but that doesn't exist. There's two other files there, but b65bd9b4fec7f6a7b0b3313c68199a18804327
doesn't exist.
我检查了目录,.git/objects/53/b65bd9b4fec7f6a7b0b3313c68199a18804327
但它不存在。那里还有另外两个文件,但b65bd9b4fec7f6a7b0b3313c68199a18804327
不存在。
回答by Vasilisfoo
I had the same problem and the only solution that I found was to navigate to the head like so :
我遇到了同样的问题,我找到的唯一解决方案是像这样导航到头部:
.git/refs/heads/branch_name
.git/refs/heads/branch_name
And I deleted the head file . Then I went to the console and I used the command :
我删除了头文件。然后我去了控制台并使用了命令:
git reset
Then all the files were unstaged so add them and commit them afterwards.
然后所有文件都未暂存,因此添加它们并在之后提交它们。
回答by Rafael Marques
I had the same problem, this worked for me:
我遇到了同样的问题,这对我有用:
Step 1)- got to .git\logs\refs\headsand open the Document named as YOUR_BRANCH, now copy the ID-numbers in front of your user name and email-
步骤 1)- 到.git\logs\refs\heads并打开名为YOUR_BRANCH的文档,现在复制 您的用户名和电子邮件前面的ID-numbers-
Step 2)- got to .git\refs\headsand open the document named as YOUR_BRANCHdelete the line and paste the IDin.
步骤 2)- 到.git\refs\heads并打开名为YOUR_BRANCH的文档, 删除该行并粘贴ID。
Hope it works for you to
希望它对你有用
回答by ASCII ALIEN
Worked for me, into terminal enter: (branch accordingly to your desires lul)
对我来说有效,进入终端输入:(根据你的愿望分支)
echo ref: refs/heads/master >.git/HEAD
回答by Sandip Subedi
This is what fixed my issue:
这就是解决我的问题的原因:
rm -rf .git/refs/heads/
回答by David La Grange
When I run into this I just git clone the project into a new file directory and pull the heads folder from located at .git\refs\heads and replace the original heads file in the directory that your having the problem. Then just delete the new clone you created (since it obviously doesn't have the updates your trying to push).
当我遇到这个问题时,我只是将项目 git clone 到一个新的文件目录中,然后从 .git\refs\heads 中拉出 head 文件夹,然后替换出现问题的目录中的原始 head 文件。然后只需删除您创建的新克隆(因为它显然没有您尝试推送的更新)。
回答by Chiaro
If you don't mind losing your history, you can delete the .git file and then
如果你不介意丢失你的历史记录,你可以删除 .git 文件,然后
git init
This will reinitialize your repository and you can then proceed from there
这将重新初始化您的存储库,然后您可以从那里继续
回答by dev-null
I had the same issue after calling git commands with the root user inside the working copy. So the owner and owner group of various files under .git/ were changed to "root".
在工作副本中使用 root 用户调用 git 命令后,我遇到了同样的问题。于是将.git/下的各种文件的所有者和所有者组改为“root”。
When I switched back to my user account, git could not handle this files anymore, because of the lacking permissions.
当我切换回我的用户帐户时,由于缺乏权限,git 无法再处理这些文件。
It worked again, after resetting the permissions with
重新设置权限后,它再次工作
sudo chown -R [MY_USER]:[MY_GROUP] .git
回答by Krzysztof Walczewski
I have the same problem. I just used command:
我也有同样的问题。我刚刚使用了命令:
git reset
Than I removed file /my_project_directory/./git/refs/heads/master and than I can use command
比我删除文件 /my_project_directory/./git/refs/heads/master 比我可以使用命令
git reset --hard <my_hash_of_last_commit_on_remote_branch>