Git 跟踪整个主目录。获取错误 - 致命:错误的默认修订版“HEAD”

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

Git tracking entire home directory. Get error - fatal: bad default revision 'HEAD'

git

提问by Kojo Opuni

I'm completely new to git. I'm working in Mac Terminal.

我对 git 完全陌生。我在 Mac 终端工作。

Whenever I do a git statusin my home directory, all untracked files, files in the stage directory, and committed files in my entire home directory appear. When I do a git login my home directory, I get the following error:

每当我git status在我的主目录中执行 a时,所有未跟踪的文件、stage 目录中的文件和我整个主目录中的已提交文件都会出现。当我git log在主目录中执行 a时,出现以下错误:

fatal: bad default revision 'HEAD'

致命:错误的默认修订版“HEAD”

How do I go about correcting this error? How do I get git to stop tracking the contents of my entire home directory without affecting it in its current state?

我该如何纠正这个错误?如何让 git 停止跟踪我整个主目录的内容而不影响它的当前状态?

Thanks in advance, and I apologize for my ignorance. I just do not want to do anything that could be potentially damaging to my home directory.

提前致谢,我为我的无知道歉。我只是不想做任何可能对我的主目录造成损害的事情。

When I enter git statusin the main directory, I get the following:

当我进入git status主目录时,我得到以下信息:

~ (master) > Kojo$ git status
 On branch master

Initial commit

 Changes to be committed:
   (use "git rm --cached <file>..." to unstage)

    new file:   Desktop/Classes/Person.cpp
    new file:   Desktop/Classes/Person.h
    new file:   Desktop/Classes/Tweeter.cpp
    new file:   Desktop/Classes/Tweeter.h
    new file:   Documents/AoGPMidterm/xcode/TriMesh.h
    new file:   Projects/Testing/Testing/ConditionalClass.cs
    new file:   Projects/Testing/Testing/Lucky_Num.cs
    new file:   Projects/Testing/Testing/NewEnum.cs

 Changes not staged for commit:
   (use "git add/rm <file>..." to update what will be committed)
   (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    Desktop/Classes/Person.cpp
    deleted:    Desktop/Classes/Person.h
    deleted:    Desktop/Classes/Tweeter.cpp
    deleted:    Desktop/Classes/Tweeter.h
    modified:   Documents/AoGPMidterm/xcode/TriMesh.h
    modified:   Projects/Testing/Testing/Lucky_Num.cs

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

    .3dequalizer/
    .Assimilate/
    .CFUserTextEncoding
    .MacOSX/
    .adobe/
    .android/
    .appletviewer
    .bash_git
    .bash_history
    .bash_profile
    .bashrc
    .bashrcecho
    .bitrock/
    .cache/
    .codeintel/
    .config/
    .cptzzscn

回答by RyPeck

The reason for that error is because you haven't made an initial commit. But it also looks like you initialized the git repository in the wrong directory.

该错误的原因是因为您尚未进行初始提交。但看起来您在错误的目录中初始化了 git 存储库。

It looks like you ran the git initcommand in the wrong directory. Navigate to the directory you originally ran that command in (Looks like it was your Home Directory).

看起来您git init在错误的目录中运行了该命令。导航到您最初运行该命令的目录(看起来它是您的主目录)。

Run ls -lato see all the files in your current directory. You should see a .gitdirectory. This contains all of data git uses to keep track of your work for a repository. Remove that you'll be back just like you were before you ran git. Since you haven't committed any work to the repo, you can safely remove it.

运行ls -la以查看当前目录中的所有文件。您应该会看到一个.git目录。这包含 git 用来跟踪存储库工作的所有数据。删除您将像运行 git 之前一样返回的信息。由于您尚未向 repo 提交任何工作,因此您可以安全地将其删除。

In the future you should run git initin a folder specifically for the project you are working on. All the files and subfiles in that folder should be for your project.

将来,您应该git init在专门用于您正在处理的项目的文件夹中运行。该文件夹中的所有文件和子文件都应该用于您的项目。

If you are just getting started using git, I highly recommend the Pro Git book, available for free online.

如果您刚刚开始使用 git,我强烈推荐Pro Git 书籍,可在线免费获得。

回答by Kojo Opuni

I'm not sure if this is what happened in your case, but you can get the error message from git log

我不确定这是否是您的情况,但您可以从 git log

fatal: bad default revision 'HEAD'

致命:错误的默认修订版“HEAD”

if you just made your repo, and you haven't made any commits in it yet. If this is your case, then simply add your files, commit them, and do the log again:

如果你刚刚制作了你的 repo,并且你还没有在其中进行任何提交。如果这是您的情况,那么只需添加您的文件,提交它们,然后再次执行日志:

$ git add "*"
$ git commit -m "Your commit message"
$ git log