Git 的问题(HEAD 指向一个未出生的分支(主))
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8551278/
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
Issues with Git (HEAD points to an unborn branch (master))
提问by lysergic-acid
I have a Git repository with 'master' branch. Some time ago (few months), we stopped using master, and created a new branch that all work is being done on.
我有一个带有“master”分支的 Git 存储库。前段时间(几个月),我们停止使用 master,并创建了一个新的分支,所有工作都在上面完成。
I am now setting up source indexing with git, and for some reason i am seeing weird stuff with the new branch:
我现在正在使用 git 设置源索引,出于某种原因,我在新分支上看到了奇怪的东西:
Running git logfails:
fatal: bad default revision 'HEAD'
Running git fsckresults in this:
notice: HEAD points to an unborn branch (master) notice: No default references dangling commit 81f11e0b99ad38ecc8502bbed171d2bdfcaa6476
运行git log失败:
致命:错误的默认修订版“HEAD”
运行git fsck结果如下:
注意:HEAD 指向一个未出生的分支(主) 注意:没有默认引用悬空提交 81f11e0b99ad38ecc8502bbed171d2bdfcaa6476
I think that something is not right with this repository/branch which is causing problems with the source indexing scripts.
我认为这个存储库/分支有问题,导致源索引脚本出现问题。
Any ideas? (Note that the REAL issue here is that the source indexing script fails to get the object id it is trying to lookup using git show, it says that no such object exists).
有任何想法吗?(请注意,这里的真正问题是源索引脚本无法获取它尝试使用 git show 查找的对象 ID,它表示不存在这样的对象)。
回答by CB Bailey
You don't have to have a master branch but you do have to have a "default" branch in any git repository. In a non-bare repository this the checked out branch, in a bare repository it just means it's the default branch checked out for clones.
你不必有一个 master 分支,但你必须在任何 git 存储库中有一个“默认”分支。在非裸存储库中,这是签出的分支,在裸存储库中,它仅意味着它是为克隆签出的默认分支。
This default branch is called HEAD
and must always exist in a valid git repository. If you've removed the branch that HEAD
was pointing at you can reset to a valid branch it with:
这个默认分支被调用HEAD
并且必须始终存在于有效的 git 存储库中。如果您删除了HEAD
指向的分支,则可以使用以下命令将其重置为有效分支:
git symbolic-ref HEAD refs/heads/new-main-branch
回答by Warbo
This happened to me due to some corruption, and the answer from @CBBailey didn't work at first.
由于一些腐败,这发生在我身上,@CBBailey 的回答起初不起作用。
To fix the previous corruption I had pushed from my working clone like:
为了修复我从我的工作克隆中推送的先前损坏,例如:
git push origin :refs/heads/master
This caused the refs/heads/
directory of the bare repo to be empty, hence why I encountered this problem of HEAD
pointing to an "unborn branch". In my case this was resolved by just doing another:
这导致refs/heads/
裸仓库的目录为空,因此我遇到了HEAD
指向“未出生分支”的问题。在我的情况下,这只是通过做另一个来解决的:
git push --all
This put refs/heads/master
back in place, so HEAD
worked again.
这refs/heads/master
放回原位,所以HEAD
再次工作。