gpt4 book ai didi

Git 子模块添加 : "a git directory is found locally" issue

转载 作者:IT王子 更新时间:2023-10-29 01:18:30 24 4
gpt4 key购买 nike

我实际上正在尝试学习如何使用 git,包括 git submodule 子命令。我已经设置了一个服务器,我可以在上面使用 SSH 托管、推送和 pull git 存储库。我在此服务器上创建了一个主 git 存储库“Travail”,我想将我的所有项目作为子模块放入其中。

在我的 Travail 存储库中,我已经在 tools/libft 中添加了一个我的项目作为子模块:我能够开发这个子模块,推 pull 它。

但是当我尝试添加另一个子模块(名为 fdf,来 self 服务器上的 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://git@XXX.XXX.XXX.XXX: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/中其实没有子目录

我在另一个线程上读到我应该使用 git submodule sync 或编辑 .gitmodules 文件,其中我的子模块的原始存储库的 URL 可能已更改。

但是我的 .gitmodules 文件只包含关于我的第一个子模块(tools/libft)的信息,而不是关于 projets/fdf 的信息:

[submodule "tools/libft"]
path = tools/libft
url = ssh://git@XXX.XXX.XXX.XXX:XXXXX/opt/git/libft.git

作为一名法国学生,我可能会遗漏英语文档中的某些内容,但我进行了搜索,但我真的不明白为什么会遇到这个问题。

如果我能得到一个解决方案,我会很高兴,但只是一个解释也会有帮助。

最佳答案

我来到这个 SO post 试图添加一个与我最近删除的子模块具有相同路径的子模块。

这就是最终对我有用的(this article helped out a lot):

如果你还没有运行
git rm --cached path_to_submodule(没有尾部斜杠)以及
rm -rf path_to_submodule

然后:

  1. .gitmodules 文件中删除相关行。例如删除这些:
[submodule "path_to_submodule"]
path = path_to_submodule
url = https://github.com/path_to_submodule
  1. 从 .git/config 中删除相关部分。例如删除这些:
[submodule "path_to_submodule"]
url = https://github.com/path_to_submodule
  1. rm -rf .git/modules/path_to_submodule

然后,你终于可以:

git子模块添加https://github.com/path_to_submodule

关于Git 子模块添加 : "a git directory is found locally" issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com