git: 致命: 带有所有新存储库的错误默认修订版“HEAD”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25087532/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:15:27  来源:igfitidea点击:

git: fatal: bad default revision 'HEAD' with all new repos

git

提问by Ravenous

The issue was a heavy amount of shell customization.

问题是大量的外壳定制。

If I try to create a new repo with git initit gives me fatal: bad default revision 'HEAD'twice.

如果我尝试用git init它创建一个新的 repo,它会给我fatal: bad default revision 'HEAD'两次。

If I do git logit gives me the same error three times.

如果我这样做,git log它会给我三次相同的错误。

I have deleted ~/.git, ~/.config, and ~/.gitconfigbased on other answers I've found stating I might have created the repo in my home directory. The only repo that doesn't give me this issue is the one I cloned from someone else.

我已经删除了~/.git, ~/.config, 并~/.gitconfig根据我发现的其他答案说明我可能已经在我的主目录中创建了 repo。唯一没有给我这个问题的 repo 是我从别人那里克隆的那个。

I'm unsure what I did besides deleting anything in my home directory with git info in it.

除了删除主目录中包含 git 信息的任何内容之外,我不确定我做了什么。

As per request:

按要求:

jsw:~ jsw$ mkdir test
jsw:~ jsw$ cd test
jsw:test jsw$ git init
Initialized empty Git repository in /Users/jsw/test/.git/
fatal: bad default revision 'HEAD'
fatal: bad default revision 'HEAD'
jsw:test(master|23448707m) jsw$ cat .git/HEAD
ref: refs/heads/master
fatal: bad default revision 'HEAD'
fatal: bad default revision 'HEAD'


jsw:~ jsw$ git status
fatal: Not a git repository (or any of the parent directories): .git

回答by eslimaf

You maybe getting this error because you don't have any commits on your HEAD revision, so when you make a git logit won't find any commit on the HEAD.

您可能会收到此错误,因为您在 HEAD 修订版上没有任何提交,因此当您进行修改时,git log它不会在 HEAD 上找到任何提交。

Please try:

请尝试:

mkdir test
cd test
git init
git commit -m 'Initial Commit' --allow-empty
git log

回答by Edward Thomson

You ran cat .git/HEADand it replied:

你跑了cat .git/HEAD,它回答说:

ref: refs/heads/master
fatal: bad default revision 'HEAD'
fatal: bad default revision 'HEAD'

Since catis not a gitcommand and doesn't care about your HEAD, I suspect that you have configured your shell to do something like print the name of the current branch.

由于cat不是git命令并且不关心您的HEAD,我怀疑您已将 shell 配置为执行诸如打印当前分支名称之类的操作。

In fact, looking at your shell prompt:

事实上,看看你的 shell 提示:

jsw:test(master|23448707m) jsw$

I'm certain of it.

我很确定。

Either turn off whatever shell magic you are trying to perform, fix it so that it knows how to deal with new repositories, or simply cope with the error messages until you've made your first commit.

要么关闭您尝试执行的任何 shell 魔法,修复它以便它知道如何处理新的存储库,要么在您进行第一次提交之前简单地处理错误消息。

回答by Ganga Ramesh

please use the below command

请使用以下命令

git init git commit -m 'initial commit' --allow-empty git log

git init git commit -m '初始提交' --allow-empty git log

Then you run the reflog you will see ref#

然后你运行 reflog 你会看到 ref#