git - IntelliJ 错误 : branch 'origin/HEAD' does not point at a commit, 无法读取某些引用

标签 git intellij-idea

据我所知,我的 git 本地存储库中的所有内容都很好。我可以提交、 push 、 pull 任何我喜欢的东西。

但是,当我在 IntelliJ 日志中查看提交的详细信息时,Contained in branches:

Can not load branches due to error:
error: branch 'origin/HEAD' does not point at a commit 
error: some refs could not be read 
error: branch 'origin/HEAD' does not point at a commit 
error: some refs could not be read

这可能是什么原因造成的,我该如何解决?

最佳答案

origin/head听起来像是在您的远程源 repo 中设置的默认分支。例如,当我做 git branch -a ,我看到这个出现在列表中:

remotes/origin/HEAD -> origin/master

如果远程中的默认分支发生更改,并且旧的默认分支已被删除,您可能会在本地存储库中丢失此引用,或者您的本地存储库的引用可能已过时。

可能的解决方案

如果这确实是您的 IDE 错误的原因,那么您可以使用 git symbolic-ref 手动更正它。 :

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/<default-branch>

在哪里<default-branch>是远程仓库中的默认分支。

更新的解决方案

所以 git 实际上有一个更方便的命令,可用于将本地仓库的符号引用更新为远程仓库中的默认分支:

git remote set-head <remote> --auto

# Or shorter
git remote set-head <remote> -a

它是在 commit bc14fac 中介绍的用于 git 1.6.3(2009 年 5 月)。

Sets or deletes the default branch ($GIT_DIR/remotes/<name>/HEAD) for the named remote.
Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch.
For example, if the default branch for origin is set to master, then origin may be specified wherever you would normally specify origin/master.

关于git - IntelliJ 错误 : branch 'origin/HEAD' does not point at a commit, 无法读取某些引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18570982/

相关文章:

ruby-on-rails - 部署到 heroku 时出错

git - pull 请求数量高于我的存储库中的预期数量?

visual-studio-2010 - 如何在 Visual Studio 2010 中快速切换源代码控制提供程序?

javascript - Webstorm 7 无法识别 Node API 方法

scala - 这个 sbt 文件有什么问题?

java - 如何让 IntelliJ IDEA 从 Gradle 配置中尊重 user.language 和 user.country?

git - 将 git 标签转换为分支

git - 如何将 git 存储库中的内容与结构分开?

android - 无法在 android studio 3.6 中进行 git pull

java - IntelliJ IDEA - 显示异常跟踪