Git“致命:没有这样的参考:HEAD”
我的 git 存储库发生了一件奇怪的事情。当我尝试在 tortoisegit 窗口中提交某些内容时,我收到了项目中的所有文件。我无法恢复它们,当我从服务器拉取时,我收到 fatal: No such ref: HEAD
和 fatal: Cannot lock the ref 'HEAD'
。我所有的当地分支机构都不见了。有什么办法可以解决这个问题吗?
这不是第一次提交或其他什么。这件事发生得很突然。
编辑:
git分支-a
说:无法将HEAD解析为有效的引用
git status
打印所有标记为新文件的项目文件。
我更改了存储库文件夹名称一段时间,当我将其更改回来时,情况不正确。
A weird thing happend to my git repository. When I try to commit something in tortoisegit window I receive all files from project. I cannot revert them, when I pull from server I receive fatal: No such ref: HEAD
and fatal: Cannot lock the ref 'HEAD'
. All my local branches are missing. Is there any way to resolve the problem?
This is not first commit or something. This thing happend suddenly.
EDIT:
git branch -a
says: Failed to resolve HEAD as a valid ref
git status
prints all project files marked as new file.
I changed repository folder name for a while, and when I changed it back things were not correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您丢失了
HEAD
,因此您需要重新创建它。最简单的事情就是这样。现在您应该能够运行其他 git 命令并查看当前位置。
(尽管从理论上讲,您可以尝试执行
git symbolic-ref HEAD refs/heads/master
较新的 git 版本不会将.git
识别为 git 存储库,除非它已经包含一个HEAD
因此这无法创建一个新的。)You've lost your
HEAD
so you'll need to recreate it. The simplest thing to do is this.Now you should be able to run other git commands and see where you're at.
(Although, in theory, you could attempt to do
git symbolic-ref HEAD refs/heads/master
newer git versions don't recognize a.git
as a git repository unless it already contains aHEAD
so this won't work to create a new one.)HEAD
通常是对特定分支的引用;在您的情况下,分支指针似乎丢失了,因此无法解析 HEAD 引用。您可以使用 git fsck --lost-found 扫描对象缓存以查找无法访问的对象;具体来说,您对提交感兴趣,可以在
.git/lost-found/commit/
下面找到它;这些是指向您的分支的指针,您所需要做的就是找出哪个是哪个,并使用 gitbranch 创建新的引用。HEAD
is usually a reference to a particular branch; in your case, it seems the branch pointers have gone missing, so the HEAD reference cannot be resolved.You can use
git fsck --lost-found
to scan the object cache for unreachable objects; specifically, you are interested in commits, which can then be found below.git/lost-found/commit/
; these are pointers to your branches, all you need to do then is find out which is which, and create new references usinggit branch
.我认为这个答案可能对某人有帮助。
我几乎解决了这个问题。
首先,我所做的是,就像 Charles Bailey 写的那样,使用
然后我的分支更改为 master。我提交了更改并能够切换到我的主分支。问题是我无法使用我当地的任何分支机构。特别是我想在分支 812 上工作。所以我找到了对分支 812 的最后一次提交(提交时创建消息非常有帮助;))并切换到它。接下来,我根据我切换到的分支创建了 812 分支。不幸的是,一些文件丢失了。幸运的是,我把它们放在了我在“echo”之前复制的损坏的仓库中
I think this answer maybe helpful for someone.
I resolved this problem nearly.
First what I did was, like Charles Bailey wrote, use
Then my branch changed to master. I commited changes and was able to switch to my main branch. The problem was that I wasn`t able to use any of my local branches. Especially I wanted to work on branch 812. So I found last commit to branch 812 (create message when commit is very helpful ;)) and switched to it. Next I created branch 812 based on the one I switched to. Unfortunately some files were missing. Luckily I had them on the broken repo which I copied before 'echo'
对我来说,问题是在 Mac OS X 上设置了“uchg”或“uappnd”标志,无论权限如何,都会锁定一些 git 文件。我像这样重置了 chflags,它为我解决了这个问题:
For me the problem was that on Mac OS X either the 'uchg' or 'uappnd' flag was set, locking some git files regardless of the perms. I reset the chflags like this and it solved it for me: