git 错误:“已经存在并且不是有效的 git 存储库”

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

Error with git: " already exists and is not a valid git repo"

gitgithuboauth

提问by jnbdz

It is seying that I cannot do this:

我不能这样做:

 git submodule add -f [email protected]:thephpleague/oauth2-server.git libs/OAuth/functions

Because of this:

因为这:

'libs/OAuth/functions'already exists and is not a valid git repo

'libs/OAuth/functions'已经存在并且不是有效的git repo

I just don't get it. It does not exists anywhere. Is there another git config filehidden on my computer that I don't know of or something? I tried deleting .gitand pullingeverything again that did not do anything. Any ideas?

我只是不明白。它不存在于任何地方。我的计算机上是否隐藏了另一个我不知道的git 配置文件?我尝试删除.git并再次拉出没有做任何事情的所有内容。有任何想法吗?

I also tried this:

我也试过这个:

git ls-files --stage functions

When I was inside of libs/OAuth and I got nothing.

当我在 libs/OAuth 里面时,我什么也没得到。

Then I tried this:

然后我尝试了这个:

sudo git rm --cached functions

I got this error:

我收到此错误:

fatal: pathspec 'functions' did not match any files

I also tried this:

我也试过这个:

sudo git rm -r --cached functions

And got the same previous error.

并得到相同的先前错误。

采纳答案by VonC

Even if the folder doesn't exist, check the index status:

即使文件夹不存在,检查索引状态:

cd libs/OAuth
git ls-files -- functions

If there is an entry registered in the index, you will need to remove it before being able to add your subrepos as a submodule.
(as explained in "Issue with adding common code as git submodule: “already exists in the index”")

如果在索引中注册了条目,则需要先将其删除,然后才能将子存储库添加为子模块。
(如“将公共代码添加为 git 子模块的问题:“已存在于索引中”中所述

All this assumes that you are at the root folder of a currently cloned repo, which will act as the parent repo of any submodule you would declare.

所有这些都假设您位于当前克隆的 repo 的根文件夹中,它将充当您将声明的任何子模块的父 repo。

回答by Panthro

In case someone else had a similar case as mine and was struggling with this as I was because of a stupid reason:

万一其他人有和我类似的情况,并且因为一个愚蠢的原因而像我一样努力解决这个问题:

Check if for any reason the file doesn't already exists (I had a failed git subomdule add previously)

检查文件是否因任何原因不存在(我之前添加了失败的 git subomdule)

So in the context of the question rm the file:

因此,在问题 rm 文件的上下文中:

rm -rf libs/OAuth/functions

And then try to re add

然后尝试重新添加