Git - 致命:错误的缺省修订版本'HEAD'&注意:HEAD指向未出生的分支(主) [英] Git - fatal: bad default revision 'HEAD' & notice: HEAD points to unborn branch (master)

查看:1522
本文介绍了Git - 致命:错误的缺省修订版本'HEAD'&注意:HEAD指向未出生的分支(主)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这一切都是新手,目前正在上课学习git。但是,我正在实践分支和合并。我创建了一个新的分支,它被切换,但我的电脑开始出现问题,导致我关闭并重新启动。当我回到我的工作时,我回到了这里:

 > git status 
分支主

初始提交

未记录的文件:
(使用git add< file> ...包含在

.gitconfig $中b $ b AppData /
联系人/
创意云文件/
桌面/
文档/
下载/
收藏夹/
链接/
Music /
NTUSER.DAT {9f037fb3-2982-11e3-93f1-b8c
NTUSER.DAT {9f037fb3-2982-11e3-93f1-b8c00000001.regtrans-ms
NTUSER.DAT {9f037fb3-2982-11e3-93f1-b8c00000002.regtrans-ms
ntuser.dat {290469cc-4e2a-11e3-bebb-68500000002.regtrans-ms

我不知道ntuser.dat是什么意思,当我运行git fsck时,我的返回结果如下所示:



通知:HEAD指向一个未出生的分支(master)
检查对象目录:100%(256/256),done。
notice:No de错误引用



当我做git log时,我收到致命的错误错误。我试图重置,似乎没有任何工作。有人可以请我提供帮助吗?

另外,我正在使用一台PC,这需要我使用Windows的命令提示符。

解决方案

看起来就像这样发生了......


  1. 您在 C:\ Users \Sandy 中运行 git init

  2. 您可能做了其他事情。

  3. 您的计算机崩溃。

  4. 您重新启动。
  5. 无论您在#2中做了什么都不见了。

你现在看到的是一个没有提交的Git仓库,一个没有指向的主分支。创建存储库后,这很正常。在这里,我现在可以重新创建它。

  $ mkdir foo 
$ cd foo
$ git init
在/Users/schwern/tmp/foo/.git/
$ git log
中初始化的空Git存储库致命错误:错误的缺省修订版本HEAD'
$ git status
关于分支master

初始提交

没有提交(创建/复制文件并使用git add跟踪)

$ git fsck
通知:HEAD指向未出生的分支(主)
检查对象目录:100%(256/256),完成。
通知:没有默认引用

您需要做的所有事情都是 git add git commit 按照正常操作。



为什么你看到 git status 中的所有垃圾,Git存储库覆盖目录和所有子目录。如果您在 C:\ Users \ Sandy 中运行 git init ,那么存储库将尝试跟踪主目录和所有子目录。 是Windows正常隐藏的Windows管理文件。 Git并不关心一个文件是什么,并向您显示所有内容。



您可能不希望将整个主目录放入版本控制中。不是说它会伤害任何东西,它只是不实际。相反,按照我的做法创建一个新目录并在其中运行 git init



至于您的存储库主目录,只需删除它。一个Git仓库存储在项目目录下的一个 .git 子目录中。删除 C:\ Users \Sandy\.git\ ,就完成了。在我上面的例子中,它会是 foo / .git /



PS您不能运行 git init 在一个文件上,它必须在一个目录中。


I am a newbie to all this and currently taking a class to learn git. However, I was in the process of practicing branching and merging. I had created a new branch and it was switched but my computer started to have issues, which cause me to shut it down and restart. When I return to my work, I returned to this:

>git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what

        .gitconfig
        AppData/
        Contacts/
        Creative Cloud Files/
        Desktop/
        Documents/
        Downloads/
        Favorites/
        Links/
        Music/
        NTUSER.DAT{9f037fb3-2982-11e3-93f1-b8c
        NTUSER.DAT{9f037fb3-2982-11e3-93f1-b8c00000001.regtrans-ms
        NTUSER.DAT{9f037fb3-2982-11e3-93f1-b8c00000002.regtrans-ms
        ntuser.dat{290469cc-4e2a-11e3-bebb-68500000002.regtrans-ms

I have no idea of what ntuser.dat means and when I run git fsck my return looks like this:

notice: HEAD points to an unborn branch (master) Checking object directories: 100% (256/256), done. notice: No default references

When I doing git log, I receive the fatal bad error. I have tried to reset and nothing seems to be working. Can someone please provide me with assistance?

Additionally, I am using a PC, which requires me to use the command prompt for Windows.

解决方案

It looks like this happened...

  1. You ran git init in C:\Users\Sandy.
  2. You may have done other things.
  3. Your computer crashed.
  4. You rebooted.
  5. Whatever you did in #2 was lost.

What you're seeing right now is a Git repository with no commits and a master branch that points to nothing. That's normal after you've created a repository. Here, I can recreate it right now.

$ mkdir foo
$ cd foo
$ git init
Initialized empty Git repository in /Users/schwern/tmp/foo/.git/
$ git log
fatal: bad default revision 'HEAD'
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

$ git fsck
notice: HEAD points to an unborn branch (master)
Checking object directories: 100% (256/256), done.
notice: No default references

All you need to do to fix this is git add and git commit something and proceed as normal.

As for why you're seeing all that junk in git status, Git repositories cover a directory and all subdirectories. If you ran git init in C:\Users\Sandy then the repository will try to track everything in your home directory and all subdirectories. NTUSER.dat is normal Windows administrative files that Windows normally hides from you. Git doesn't care what a file is and shows you everything.

You probably don't want to put your entire home directory in version control. Not that it would hurt anything, it's just not practical. Instead, do as I did and create a new directory and run git init there.

As for your repository in the home directory, just delete it. A Git repository is stored in a .git sub-directory immediately inside your project directory. Delete C:\Users\Sandy\.git\ and you're done. In my example above, it would be foo/.git/.

PS You can't run git init on a file, it has to be in a directory.

这篇关于Git - 致命:错误的缺省修订版本'HEAD'&amp;注意:HEAD指向未出生的分支(主)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆