git Git子模块添加:“在本地找到一个git目录”问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20929336/
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: "a git directory is found locally" issue
提问by vmonteco
I'm actually trying to learn how to use git, including the git submodule
subcommands.
I already set up a server on which I can host, push and pull git repositories by using SSH.
I created a main git repository "Travail" on this server in which I would like to put all my projects as submodules.
我实际上是在尝试学习如何使用 git,包括git submodule
子命令。我已经设置了一个服务器,我可以在该服务器上使用 SSH 托管、推送和拉取 git 存储库。我在这台服务器上创建了一个主 git 存储库“Travail”,我想将所有项目作为子模块放在其中。
In my Travail repository, I already added a project of mine as a submodule at tools/libft
:
I'm able to develop this submodule, to push and to pull it.
在我的 Travail 存储库中,我已经在以下位置添加了我的一个项目作为子模块tools/libft
:我能够开发这个子模块,推和拉它。
But when I try to add another submodule (named fdf, from fdf.git on my server), I get the following issue :
但是,当我尝试添加另一个子模块(名为 fdf,来自服务器上的 fdf.git)时,出现以下问题:
git submodule add ssh://XXX.XXX.XXX.XXX:XXXXX/opt/git/fdf.git projets/fdf
A git directory for 'projets/fdf' is found locally with remote(s): origin ssh://[email protected]:XXXXX/opt/git/fdf.git If you want to reuse this local git directory instead of cloning again from ssh://XXX.XXX.XXX.XXX:XXXXX/opt/git/fdf.git use the '--force' option. If the local git directory is not the correct repo or you are unsure what this means choose another name with the '--name' option.
'projets/fdf' 的 git 目录在本地找到,远程: origin ssh://[email protected]:XXXXX/opt/git/fdf.git 如果你想重用这个本地 git目录而不是从 ssh://XXX.XXX.XXX.XXX:XXXXX/opt/git/fdf.git 再次克隆,请使用“--force”选项。如果本地 git 目录不是正确的存储库,或者您不确定这意味着什么,请使用“--name”选项选择另一个名称。
There is actually no subdirectory in projets/
实际上没有子目录 projets/
I read on another thread that I should use git submodule sync
or edit the .gitmodules file in which the URL to my submodule's origin repository could have changed.
我在另一个线程上读到我应该使用git submodule sync
或编辑 .gitmodules 文件,在该文件中,我的子模块的原始存储库的 URL 可能已更改。
But my .gitmodules file only contains the information about my first submodule (tools/libft), not about projets/fdf :
但是我的 .gitmodules 文件只包含关于我的第一个子模块(tools/libft)的信息,而不是关于 projets/fdf 的信息:
[submodule "tools/libft"]
path = tools/libft
url = ssh://[email protected]:XXXXX/opt/git/libft.git
As a French student I could have missed something in the English documentation I have, but I searched and I really don't understand why I get this issue.
作为一名法国学生,我可能会遗漏我所拥有的英文文档中的某些内容,但我进行了搜索,但我真的不明白为什么会出现此问题。
I would be glad if I would get a solution but just an explanation would be helpful too.
如果我能得到解决方案,我会很高兴,但只是一个解释也会有帮助。
回答by jbmilgrom
I came to this SO post trying to add a submodule with the same path as a submodule that I recently deleted.
我来到这个 SO 帖子试图添加一个与我最近删除的子模块具有相同路径的子模块。
This is what ultimately worked for me (this article helped out a lot):
这最终对我有用(这篇文章很有帮助):
If you haven't already run git rm --cached path_to_submodule
(no trailing slash) as well as rm -rf path_to_submodule
, do that!
如果您还没有运行git rm --cached path_to_submodule
(没有尾部斜杠)以及rm -rf path_to_submodule
,请执行此操作!
Then:
然后:
Delete the relevant lines from the
.gitmodules
file. e.g. delete these:[submodule "path_to_submodule"] path = path_to_submodule url = https://github.com/path_to_submodule
Delete the relevant section from .git/config. e.g. delete these:
[submodule "path_to_submodule"] url = https://github.com/path_to_submodule
rm -rf .git/modules/path_to_submodule
从
.gitmodules
文件中删除相关行。例如删除这些:[submodule "path_to_submodule"] path = path_to_submodule url = https://github.com/path_to_submodule
从 .git/config 中删除相关部分。例如删除这些:
[submodule "path_to_submodule"] url = https://github.com/path_to_submodule
rm -rf .git/modules/path_to_submodule
Then, you can finally:
然后,您终于可以:
git submodule add https://github.com/path_to_submodule
git submodule add https://github.com/path_to_submodule
回答by pjammer
i tried jbmilgrom's solution, specifically i tried git rm --cache
and that didn't work for me either as the directory/submodule wasn't there. What worked for me was:
我尝试了 jbmilgrom 的解决方案,特别是我尝试过git rm --cache
,但这对我不起作用,因为目录/子模块不存在。对我有用的是:
rm -rf .git/modules/blah
git submodule add git://path.to.new
rm -rf .git/modules/blah
git submodule add git://path.to.new
I did this after trying --force
within the git submodule
commands and rm
all the other directories, pushes to master etc... the directory didn't exist and there was no reason for the cache. Turns out in .git/modules
that is where this error was lying.
我--force
在git submodule
命令和rm
所有其他目录中尝试后这样做了,推送到 master 等......目录不存在并且没有理由缓存。原来.git/modules
这就是这个错误所在。
回答by bredikhin
You may have deleted your 'projets/fdf'
from disk, but your Git repository still has it. Use git rm -rf projets/fdf
to remove it from Git, then commit the changes. After that you'll be able to add this folder as a submodule.
您可能已经'projets/fdf'
从磁盘中删除了您的文件,但您的 Git 存储库仍然保留着它。使用git rm -rf projets/fdf
从Git的删除它,然后提交更改。之后,您将能够将此文件夹添加为子模块。
回答by Dmitri R117
If you already deleted the submodule directory, like I did, follow the rest of jbmilgrom's instructions. The key is rm -rf .git/modules/path_to_submodule
but go ahead and backup your whole parent repo directory first.
如果您已经像我一样删除了子模块目录,请按照 jbmilgrom 的其余说明进行操作。关键是rm -rf .git/modules/path_to_submodule
先备份整个父 repo 目录。
If you only had one submodule just delete .gitmodules
如果你只有一个子模块就删除 .gitmodules
回答by W.Perrin
These two commands works for me.
这两个命令对我有用。
rm path/to/submodule -rf
rm .git/modules/path/to/module -rf