git 子模块添加致命:不是 Git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10048783/
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
git submodule add fatal: Not a Git Repository
提问by Brandon Grossutti
I am fairly new to Git and trying my best to find some documentation on this problem to no avail.
我对 Git 相当陌生,并尽我所能找到有关此问题的一些文档,但无济于事。
Here's my command:
这是我的命令:
$ git submodule add https://github.com/joliver/EventStore.git externalsource/JOliverEventStore/
fatal: Not a git repository: ../.git/modules/externalsource/JOliverEventStore Unable to checkout submodule 'externalsource/JOliverEventStore'
致命:不是 git 存储库:../.git/modules/externalsource/JOliverEventStore 无法检出子模块“externalsource/JOliverEventStore”
I am in my root of my repo and there is currently no directory for /externalsource/JO
liverEventStore/
. The error is talking about a directory that I have no knowledge of.
我在我的 repo 的根目录中,目前没有/externalsource/JO
liverEventStore/
. 错误是在谈论我不知道的目录。
If I add the submodule to the root dir like this:
如果我像这样将子模块添加到根目录:
$ git submodule add https://github.com/joliver/EventStore.git JOliverEventStore
I have no problem and it creates the folder in the root directory.
我没有问题,它在根目录中创建了文件夹。
Any insight would be greatly appreciated.
任何见解将不胜感激。
回答by VonC
It can depends on the version of Git you are using: this recent thread (February 2012)mentions a bug:
这可能取决于您使用的 Git 版本:这个最近的线程(2012 年 2 月)提到了一个错误:
Since recently a submodule with name
<name>
has its git directory in the.git/modules/<name>
directory of the superproject while the work tree contains agitfile
pointing there.When the same submodule is added on a branch where it wasn't present so far (it is not found in the .gitmodules file), the name is not initialized from the path as it should.
This leads to a wrong path entered in thegitfile
when the.git/modules/<name>
directory is found, as this happily uses the - now empty - name.
It then always points only a single directory up, even if we have a path deeper in the directory hierarchy.
最近一个带有名称的子模块在超级项目的
<name>
目录中有它的 git 目录,.git/modules/<name>
而工作树包含一个gitfile
指向那里。当将相同的子模块添加到迄今为止不存在的分支上时(在 .gitmodules 文件中找不到),名称不会从路径初始化。
这会导致在找到目录gitfile
时输入错误的路径.git/modules/<name>
,因为这很高兴使用 - 现在为空 - 名称。
然后它总是只指向一个目录,即使我们在目录层次结构中有一个更深的路径。
But more generally, uses the <path>
argument of git submodule
:
但更一般地,使用 的<path>
参数git submodule
:
<path>
is the relative location for the cloned submodule to exist in the superproject.
- If
<path>
does not exist, then the submodule is created by cloning from the named URL.- If
<path>
does exist and is already a valid git repository, then this is added to the changeset without cloning.
This second form is provided to ease creating a new submodule from scratch, and presumes the user will later push the submodule to the given URL.
<path>
是克隆子模块在超级项目中存在的相对位置。
- 如果
<path>
不存在,则通过从命名 URL 克隆来创建子模块。- 如果
<path>
确实存在并且已经是有效的 git 存储库,则将其添加到变更集中而不进行克隆。
提供第二种形式是为了方便从头开始创建新的子模块,并假定用户稍后会将子模块推送到给定的 URL。
eoinocmentions in the commentsanother cause, which is detailed in the question "git status
returns fatal: Not a git repository but .git exists and HEAD has proper permissions
".
eoinoc在评论中提到了另一个原因,在问题“git status
返回fatal: Not a git repository but .git exists and HEAD has proper permissions
”中有详细说明。
My repo's location had changed, and I needed to update git's configuration files.
我的 repo 的位置发生了变化,我需要更新 git 的配置文件。