github 工作流 - 致命:不是 git 存储库(或任何父目录):.git

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

github workflow - fatal: not a git repository (or any of the parent directories): .git

gitmergerepository

提问by Jessica Burnett

I have a master branch and a dev branch for current development(local working copy). I need to merge changes from master onto my dev branch. Prior to merge I ran git stash and discovered the following error:

我有一个主分支和一个用于当前开发的开发分支(本地工作副本)。我需要将 master 的更改合并到我的 dev 分支上。在合并之前,我运行 git stash 并发现以下错误:

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

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

To investigate this error I ran the following commands: git statusgit branchgit remote -v. All produced the same error fatal: Not a git repository (or any of the parent directories): .git

为了研究这个错误我跑以下命令: git statusgit branchgit remote -v。都产生了相同的错误fatal: Not a git repository (or any of the parent directories): .git

I also tried resetting the origin of my branch git remote set-url origin https://github.com/Connexions/oer.exports.gitwhich produces the same result: fatal: Not a git repository (or any of the parent directories): .git

我还尝试重置我的分支的原点,这产生了相同的结果: git remote set-url origin https://github.com/Connexions/oer.exports.gitfatal: Not a git repository (or any of the parent directories): .git

I cannot commit any changes from my local working directory onto my dev branch either.

我也无法将本地工作目录中的任何更改提交到我的 dev 分支。

Does anyone have any suggestions on how to correct this issue.

有没有人对如何纠正这个问题有任何建议。

采纳答案by VonC

One way to get that error message is to somehow notbe in the git repo working tree.
See "After git cloneI get a “ fatal: Not a git repository (or any of the parent directories): .git” error" as an illustration.

获取该错误消息的一种方法是以某种方式不在git repo 工作树中。
请参阅“git clone我收到“ fatal: Not a git repository (or any of the parent directories): .git”错误后”作为说明。

It can also be cause because of a GIT_WORK_TREEenvironment variable being set to the wrong path.
Or it is seen in wrappers using git repo like rvm(see this threadfor example)

这也可能是因为GIT_WORK_TREE环境变量设置为错误的路径。
或者在使用 git repo 之类的包装器中看到它rvm(例如,请参阅此线程

In both case, resetting the situation in a new clone (which you did) usually is a good way to fix the situation.

在这两种情况下,在新的克隆中重置情况(您所做的)通常是解决这种情况的好方法。

回答by Jernej Gololicic

Check the following file:

检查以下文件:

  • your_repo_dir/.git/HEAD
  • your_repo_dir/.git/HEAD

If this content seems corrupted, this is the issue. I had the similar issue and I fixed it by replacing the content of the HEAD file with the git commit hash of the last commit from selected branch.

如果此内容似乎已损坏,则这就是问题所在。我遇到了类似的问题,我通过用所选分支的最后一次提交的 git commit 哈希替换 HEAD 文件的内容来修复它。

Commit hashes could be found under the .git/logs/refs/heads and branch_name_file

提交哈希可以在下面找到 .git/logs/refs/heads and branch_name_file

I hope it helps.

我希望它有帮助。

回答by herostwist

I had this error after having problems with visual studio git plugin.

在 Visual Studio git 插件出现问题后,我遇到了这个错误。

The solution was to rename my_repo_dir/.git/HEAD.lockto my_repo_dir/.git/HEAD

解决方案是重命名my_repo_dir/.git/HEAD.lockmy_repo_dir/.git/HEAD

Looks like something crashed after locking the head file and that killed the repo.

锁定头文件后看起来有些东西崩溃并杀死了回购。

回答by rageit

Had the same problem after I tried to push the branch to remote from Visual Studio. I renamed .git/HEAD.lock to .git/HEAD after checking its content. Now it works fine.

在我尝试将分支从 Visual Studio 推送到远程后遇到了同样的问题。在检查其内容后,我将 .git/HEAD.lock 重命名为 .git/HEAD。现在它工作正常。