git fatal 不是 git 存储库(或任何父目录).git

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

git fatal not a git repository (or any of the parent directories) .git

gitgithub

提问by xyals

fatal not a git repository (or any of the parent directories) .gitis the error I'm getting when I try to perform any git operation on my repo. I made some changes to my project which is the repo then I try to git status to look over my changes and encounter this error. I Googled this error but didn't make any progress. It seems this error is most common when trying to perform git operations in a directory that's outside the repo which isn't the case for me. Also I tried checking my ./git/HEADand ./git/logs/refs/headsboth of which are empty files. ./git/logs/refs/remotes/origin/master is also empty.

致命的不是 git 存储库(或任何父目录).git是我尝试对我的 repo 执行任何 git 操作时遇到的错误。我对我的项目(即 repo)进行了一些更改,然后我尝试 git status 查看我的更改并遇到此错误。我用谷歌搜索了这个错误,但没有取得任何进展。当尝试在 repo 之外的目录中执行 git 操作时,此错误似乎最常见,但对我而言并非如此。我还尝试检查我的./git/HEAD./git/logs/refs/heads这两个都是空文件。./git/logs/refs/remotes/origin/master 也是空的。

So from the beginning:

所以从一开始:

  • I made an Android project in this directory on one computer.
  • I initiated a git on this directory and posted it on github.
  • I followed the usual online guides for pulling this repo onto 2 other computers.
  • Made some changes on another computer, pushed the changes to the repo.
  • Then on the original computer I successfully pulled the changes.
  • After not working on the project for a few days, I made some changes on the original computer, tried to git status and this happens.
  • 我在一台电脑上的这个目录下做了一个安卓项目。
  • 我在这个目录上启动了一个 git 并将其发布到 github 上。
  • 我按照通常的在线指南将这个 repo 拉到另外两台计算机上。
  • 在另一台计算机上进行了一些更改,将更改推送到 repo。
  • 然后在原始计算机上,我成功地拉取了更改。
  • 几天没做项目后,我在原来的电脑上做了一些改动,尝试git status,结果出现了。

回答by Ikrom

In my case, accidentally .git/HEADfile was messed up with non unknown characters, but .git/ORIG_HEADfile was ok (it has commit id). So, I copied .git/ORIG_HEADcontent to .git/HEADfile. Then restarted IDE (Aptana) and everything worked fine.

就我而言,意外.git/HEAD文件被非未知字符弄乱了,但.git/ORIG_HEAD文件没问题(它有提交 ID)。所以,我将.git/ORIG_HEAD内容复制到.git/HEAD文件中。然后重新启动 IDE (Aptana),一切正常。

回答by VonC

Make sure you don't have a GIT_DIRor GIT_WORK_TREEenvironment variable set in your current session, which would point to an incorrect folder.

确保您没有在当前会话中设置GIT_DIRGIT_WORK_TREE环境变量,这会指向不正确的文件夹。

In doubt, try a:

有疑问,请尝试:

cd /path/to /your/repo
git --git-dir .git --work-tree . status

If that still fails, try at least to clone that repo again from GitHub, and add your recent changes in that new repo:

如果仍然失败,请至少尝试从 GitHub 再次克隆该存储库,并将您最近的更改添加到该新存储库中:

cd /path/to/new/clone
git --git-dir .git --work-tree /path/to /your/repo add .

(and go on working in that new clone)

(并继续在那个新克隆中工作)

回答by Bharathwaaj

I too had the same issue. The problem was my git folder was being synced by UbuntuOne cloud service. It had messed up the files by adding files appended with u1conflict. And my .git/HEAD was also messed up as .git/HEAD.u1conflict.

我也有同样的问题。问题是我的 git 文件夹被 UbuntuOne 云服务同步。它通过添加附加有 u1conflict 的文件弄乱了文件。而我的 .git/HEAD 也被搞成了 .git/HEAD.u1conflict。

Are you using any cloud collaborating services on the git? Dropbox, UbuntuOne etc. Chances are that your .git folder might have got messed up in the process of syncing.

您是否在 git 上使用任何云协作服务?Dropbox、UbuntuOne 等。很有可能你的 .git 文件夹在同步过程中被弄乱了。

回答by M. Thompson

Ensure the directory/repository name has not changed in any way from the original. I just dealt with this error, and that was the cause.

确保目录/存储库名称与原始名称没有任何变化。我刚刚处理了这个错误,这就是原因。

回答by Nagibaba

git initsolved my issue. In fact, there was not any .git folder

git init解决了我的问题。事实上,没有任何 .git 文件夹