git 致命:错误的默认修订版“HEAD”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15628720/
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: bad default revision 'HEAD'
提问by Richie
I'm using GIT as my source control system. We have it installed on one of our Linux boxes. Tortoise GIT is my windows client.
我使用 GIT 作为我的源代码控制系统。我们将它安装在我们的一台 Linux 机器上。Tortoise GIT 是我的 Windows 客户端。
This morning I checked in some changes, and tagged the code. I then did a push of my local repository to the remote repository.
今天早上我检查了一些更改,并标记了代码。然后我将本地存储库推送到远程存储库。
When I go to my repository on the unix box and type in git log
I get:
当我转到 unix 框上的存储库并输入时,git log
我得到:
fatal: bad default revision 'HEAD'
But when I do a show log
using my windows tortoiseGit
client the history comes up nicely as per below...
但是当我show log
使用我的 WindowstortoiseGit
客户端时,历史记录很好地显示如下......
---
SHA-1: f879573ba3d8e62089b8c673257c928779f71692
Initial drop of code
---
master origin/master oms-phase4-v1.0.0
SHA-1: 56176dbe45e6175b18c9f44533828806c63142ab
OMS Phase 4 - Added OMS Cust. Order No. to EDI Purchase Order Header screens
Tag Info
object 56176dbe45e6175b18c9f44533828806c63142ab
type commit
tag oms-phase4-v1.0.0
tagger Richard Riviere <[email protected]> 1364338495 +1100
---
SHA-1: 0000000000000000000000000000000000000000
Working dir changes
0 files changed
---
The code has definitely been pushed to the remote repository. I've been able to check by cloning the repository into a different directory.
代码肯定已经被推送到远程存储库。我已经能够通过将存储库克隆到不同的目录来进行检查。
Does anyone know why I am receiving the fatal: bad default revision 'HEAD'
?
有谁知道我为什么收到fatal: bad default revision 'HEAD'
?
p.s. It is a bare repository however I have created other bare repositories which have not had this problem.
ps 这是一个裸存储库,但是我创建了其他没有这个问题的裸存储库。
采纳答案by jthill
Your repo is yours, what goes on in it is entirely your business until you push or (allow a) fetch or clone. When you deleted your windows repo -- that folder didn't represent your local repo, it was your actual local repo, you deleted everything done in it that was never pushed, fetched or cloned.
你的回购是你的,在你推送或(允许)获取或克隆之前,里面发生的事情完全是你的事情。当您删除 Windows 存储库时——该文件夹不代表您的本地存储库,它是您实际的本地存储库,您删除了其中从未推送、获取或克隆的所有内容。
edit:Ah, okay, I think I see what's going on here: you pushed to your linux repo but it's not bare and you never worked in it.
编辑:啊,好吧,我想我明白这里发生了什么:你推送到你的 linux 存储库,但它不是裸露的,你从未在其中工作过。
Instead of git log
, do git log --all
. Or git checkout
some-branch-name
.
而不是git log
,做git log --all
。或者git checkout
some-branch-name
。
Then try cloning the repo locally, on your linux box; I bet it works. What are you using to serve your repo on linux? Try cd'ing into its .git directory and git daemon --base-path=. --export-all
, if that just sits there then go to your windows box and try git clone git://your.linux.box.ip
, if the daemon complains it can't bind add --port=54345
to the daemon invoke and :54345
to the clone url.
然后尝试在您的 linux 机器上本地克隆 repo;我敢打赌它有效。你用什么来在 linux 上提供你的 repo?尝试 cd 进入它的 .git 目录git daemon --base-path=. --export-all
,如果它只是坐在那里,那么去你的 windows 框并尝试git clone git://your.linux.box.ip
,如果守护进程抱怨它无法绑定添加--port=54345
到守护进程调用和:54345
克隆 URL。
回答by Alice Purcell
This happens to me when the branch I'm working in gets deleted from the repository, but the workspace I'm in is not updated. (We have a tool that lets you create multiple git "workspaces" from the same repository using simlinks.)
当我正在工作的分支从存储库中删除时,就会发生这种情况,但我所在的工作区没有更新。(我们有一个工具可以让您使用 simlinks 从同一个存储库创建多个 git“工作区”。)
If git branch
does not mark any branch as current, try doing
如果git branch
没有将任何分支标记为当前,请尝试执行
git reset --hard <<some branch>>
I tried a number of approaches until I worked this one out.
我尝试了多种方法,直到我解决了这个问题。
回答by JRomio
just do an initial commit and the error will go away:
只需进行初始提交,错误就会消失:
git commit -m "initial commit"
回答by linquize
Not committed yet?
还没承诺?
It is a orphan branch if it has no commit.
如果它没有提交,它就是一个孤儿分支。
回答by VonC
Note: Git 2.6 (Q3/Q4 2015) will finallyprovide a more meaningful error message.
注意:Git 2.6(2015 年第三季度/第四季度)最终将提供更有意义的错误消息。
See commit ce11360(29 Aug 2015) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
--in commit 699a0f3, 02 Sep 2015)
请参阅Jeff King ( )提交的 ce11360(2015 年 8 月 29 日)。(由Junio C Hamano合并-- --在提交 699a0f3,2015 年 9 月 2 日)peff
gitster
log
: diagnose emptyHEAD
more clearlyIf you init or clone an empty repository, the initial message from running "
git log
" is not very friendly:
log
:HEAD
更清楚地诊断空如果您初始化或克隆一个空存储库,则运行“
git log
”的初始消息不是很友好:
$ git init
Initialized empty Git repository in /home/peff/foo/.git/
$ git log
fatal: bad default revision 'HEAD'
Let's detect this situation and write a more friendly message:
让我们检测这种情况并写一个更友好的消息:
$ git log
fatal: your current branch 'master' does not have any commits yet
We also detect the case that 'HEAD' points to a broken ref; this should be even less common, but is easy to see.
Note that we do not diagnose all possible cases. We rely onresolve_ref
, which means we do not get information about complex cases. E.g., "--default master
" would usedwim_ref
to find "refs/heads/master
", but we notice only that "master
" does not exist.
Similarly, a complex sha1 expression like "--default HEAD^2
" will not resolve as a ref.But that's OK. We fall back to a generic error message in those cases, and they are unlikely to be used anyway.
Catching an empty or broken "HEAD" improves the common case, and the other cases are not regressed.
我们还检测到“HEAD”指向损坏的引用的情况;这应该更不常见,但很容易看到。
请注意,我们不会诊断所有可能的情况。我们依赖resolve_ref
,这意味着我们无法获得有关复杂案例的信息。例如,"--default master
" 将用于dwim_ref
查找 "refs/heads/master
",但我们只注意到 "master
" 不存在。
类似地,像“--default HEAD^2
”这样的复杂 sha1 表达式不会解析为 ref。不过没关系。在这些情况下,我们退回到通用错误消息,无论如何都不太可能使用它们。
捕获一个空的或损坏的“HEAD”会改善常见情况,而其他情况不会回归。
回答by user2394284
Make sure branch "master" exists! It's not just a name apparently.
确保分支“master”存在!这显然不仅仅是一个名字。
I got this error after creating a blank bare repo, pushing a branch named "dev" to it, and trying to use git log in the bare repo. Interestingly, git branch knows that dev is the only branch existing (so I think this is a git bug).
在创建一个空白的裸存储库,将一个名为“dev”的分支推送到它并尝试在裸存储库中使用 git log 后,我收到了这个错误。有趣的是, git branch 知道 dev 是唯一存在的分支(所以我认为这是一个 git bug)。
Solution: I repeated the procedure, this time having renamed "dev" to "master" on the working repo before pushing to the bare repo. Success!
解决方案:我重复了这个过程,这次在推送到裸仓库之前在工作仓库上将“dev”重命名为“master”。成功!
回答by Trebor Rude
This seems to occur when .git/HEAD
refers to a branch which does not exist. I ran into this error in a repo that had nothing in .git/refs/heads
. I have no idea how the repo got into that state, I inherited from someone that left the company.
当.git/HEAD
引用不存在的分支时,似乎会发生这种情况。我在一个没有任何内容的回购中遇到了这个错误.git/refs/heads
。我不知道回购是如何进入那种状态的,我是从离开公司的人那里继承来的。
回答by Bryce Johnson
I don't think this is OP's problem, but if you're like me, you ran into this error while you were trying to play around with git plumbing commands (update-index
& cat-file
) without ever actually committing anythingin the first place. So try committing something (git commit -am 'First commit'
) and your problem should be solved.
我不认为这是 OP 的问题,但是如果您像我一样,在尝试使用 git 管道命令 ( update-index
& cat-file
) 时遇到了这个错误,而实际上从未真正提交过任何内容。所以尝试提交一些东西 ( git commit -am 'First commit'
) 并且你的问题应该得到解决。
回答by user3731622
I got the same error and couldn't solve it.
我遇到了同样的错误,无法解决。
Then I noticed 3 extra files in one of my directories.
然后我注意到我的一个目录中有 3 个额外的文件。
The files were named:
这些文件被命名为:
config, HEAD, description
I deleted the files, and the error didn't appear.
我删除了文件,错误没有出现。
config
contained:
config
包含:
[core]
repositoryformatversion = 0
filemode = true
bare = true
HEAD
contained:
HEAD
包含:
ref: refs/heads/master
description
contained:
description
包含:
Unnamed repository; edit this file 'description' to name the repository.