Git子模块添加:“在本地找到git目录”问题 [英] Git submodule add: "a git directory is found locally" issue

查看:766
本文介绍了Git子模块添加:“在本地找到git目录”问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我正在学习如何使用git,包括git子模块子命令。
我已经建立了一个服务器,我可以通过ssh托管,推送和拉动git存储库。
我在这个服务器上创建了一个主要的git仓库Travail,我希望把我所有的项目作为子模块。



在我的Travail仓库中,已经在 tools / libft 中添加了一个我的项目作为子模块:
我可以开发这个子模块来推拉它。



但是,当我尝试添加其他子模块(从我的服务器上的fdf.git命名为fdf时)时,出现以下问题:

  git submodule add ssh://XXX.XXX.XXX.XXX:XXXXX / opt / git / fdf.git projets / fdf 


'projets / fdf'的git目录是在远程本地找到的:
origin ssh://git@XXX.XXX.XXX.XXX:XXXXX / opt / git / fdf.git
如果你想重用这个本地git目录,而不是从
中再次克隆ssh:// XXX .XXX.XXX.XXX:XXXXX / opt / git / fdf.git
使用'--force'选项。如果本地git目录不是正确的repo
,或者您不确定这意味着用'--name'选项选择另一个名称。


实际上在 projets /

中没有子目录

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



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

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

作为一名法国学生,我可能在我的英文文档中遗漏了一些东西,但是我搜索过,我真的不明白为什么我会遇到这个问题。



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

解决方案

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

这是最终为我工作的东西( git rm - > -cached path_to_submodule (无尾随斜线)以及 rm -rf path_to_submodule ,做到这一点!



然后:


  1. 删除 .gitmodules 文件。例如删除这些:

    [submodulepath_to_submodule]
    path = path_to_submodule
    url = https://github.com / path_to_submodule


  2. 从.git / config中删除相关部分。例如删除这些:

    [submodulepath_to_submodule]
    url = https://github.com/path_to_submodule


然后,你可以终于:

git submodule add https ://github.com/path_to_submodule


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 on this server a main git repository "Travail" in wich I would like to put all my projects as submodules.

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.

But when I try to add an other submodule (named fdf, from fdf.git on my server), I get the following issue :

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.

There is actually no subdirectory in projets/

I read on an other 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.

But my .gitmodules file only contains the information about my first submodule (tools/libft), not about projets/fdf :

[submodule "tools/libft"]
    path = tools/libft
    url = ssh://git@XXX.XXX.XXX.XXX: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.

解决方案

I came to this SO post trying to add a submodule with the same path as a submodule that I recently deleted.

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!

Then:

  1. 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

  2. Delete the relevant section from .git/config. e.g. delete these:

    [submodule "path_to_submodule"] url = https://github.com/path_to_submodule

  3. rm -rf .git/modules/path_to_submodule

Then, you can finally:

git submodule add https://github.com/path_to_submodule

这篇关于Git子模块添加:“在本地找到git目录”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆