指定为相对路径时,不能添加git子模块 [英] Can't add git submodule when specified as a relative path

查看:173
本文介绍了指定为相对路径时,不能添加git子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

我试图添加一个子模块到我的git仓库中,远程原点没有在.git / config中定义的URL

关于这可能是什么的任何想法?我尝试了谷歌搜索,但只有一个模糊的链接出现。



我这样做:

  git submodule add ../extern/Lib1 lib 

我是期望这创建一个子模块 lib / Lib1

我知道这只会创建一个引用,然后我必须更新/ init(在这部分不清晰,没有得到那么多;我只是学习子模块命令)。

解决方案

../ extern / Lib1 引用Git存储库?

如果没有,Git不知道如何将Git repo url它的 .gitmodule

另外,试试:


  • 用目的地 lib not 已存在(甚至为空)

  • 带有绝对路径而不是相对路径(你可以使用相对的,但以防万一,这里值得一试)



es是:



< hr>

因为只有绝对路径在这里工作,所以它意味着相对路径需要一个引用来进行比较。

该引用是远程原点应位于 DirName / NewRepo_withSubmodules / .git / config 文件中,如下所示:

  $ cat .git / config 
...
[remoteorigin]
url = /path/to/DirName/NewRepo_withSubmodules/.git
fetch = + refs / heads / *:refs / remotes / origin / *
...

如果您在 ../ DirName / NewRepo_withSubmodules / .git / config 文件中包含该部分,则应该可以添加 .. / extern / lib1 作为使用相对路径的子模块。



以上所有内容都来自git子模块手册页的以下部分:


< repository> 是新子模块的源存储库的URL。
这可以是绝对URL或(如果它以 ./ ../

所以如果 NewRepo_withSubmodules 是刚刚创建的本地Git仓库(当然没有起源),应该定义一个人为的远程原点(即使原点指向它自己),如果仅允许使用其他子模块存储库的相对URL。






Git 2.13(Q2 2017)将改进检测子模块的默认原点。

请参阅 stefanbeller

(由 Junio C Hamano - 提交 gitster
- 2017年3月10日)


子模块init :警告回落到本地路径


现已记录下


<库&克t; 是新子模块的源存储库的URL。

这可以是绝对URL或(如果它以 ./ ../ ),相对于超级项目的默认远程仓库的位置

(请注意,要指定仓库' code> foo.git
',它位于超级项目' bar.git '的旁边,您必须使用' ../ foo.git '而不是' ./ foo.git ' - 正如人们所预料的那样,相对URL的规则 - 因为Git中的相对URL的评估与相关目录的相同)。



默认远程是远程跟踪分支的远程当前分支。

如果不存在这样的远程跟踪分支或 HEAD 被分离, origin 假定为默认远程。

如果超级项目没有配置默认远程,超级项目是它自己的权威上游和现在。使用
工作目录。



I'm trying to add a submodule to my git repo, and I'm getting this error in return:

remote origin does not have a url defined in .git/config

any ideas about what this might be? I tried googling for it but only one vague link comes up.

I'm doing this:

git submodule add ../extern/Lib1 lib  

I'm expecting this to create a submodule lib/Lib1
I'm aware that this will only create a reference and that I then have to update/init (not crystal clear on this part, haven't gotten that far; I'm just learning the submodule command).

解决方案

Does ../extern/Lib1 refer to a Git repository?
If it does not, Git wouldn't know how to had the Git repo url to its .gitmodule
Also, try:

  • with the destination lib not already existing (even empty)
  • with an absolute path instead of a relative path (you can use a relative one, but just in case, it is worth a try here)

Some good sources on submodules are:


Since only the absolute path works here, it means the relative path need a reference to be compared against.
That reference is the "remote origin" which should be in your DirName/NewRepo_withSubmodules/.git/config file, like so:

$ cat .git/config
    ...
    [remote "origin"]
    url = /path/to/DirName/NewRepo_withSubmodules/.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    ...

If you do have that section in ../DirName/NewRepo_withSubmodules/.git/config file, you should be able to add ../Extern/Lib1 as a submodule using a relative path.

All the above is inspired from the following section of the git submodule man page:

<repository> is the URL of the new submodule's origin repository.
This may be either an absolute URL, or (if it begins with ./ or ../), the location relative to the superproject's origin repository.

So if NewRepo_withSubmodules is a local Git repo which has just been created (and has of course no "origin"), an artificial "remote origin" ought to be defined (even if the origin points to itself), if only to allow relative url for other submodule repositories to be used.


Git 2.13 (Q2 2017) will improve the detection of the default origin of a submodule.

See commit d1b3b81 (25 Feb 2017) by Stefan Beller (stefanbeller).
(Merged by Junio C Hamano -- gitster -- in commit ae900eb, 10 Mar 2017)

submodule init: warn about falling back to a local path

As now documented:

<repository> is the URL of the new submodule's origin repository.
This may be either an absolute URL, or (if it begins with ./ or ../), the location relative to the superproject's default remote repository
(Please note that to specify a repository 'foo.git' which is located right next to a superproject 'bar.git', you'll have to use '../foo.git' instead of './foo.git' - as one might expect when following the rules for relative URLs - because the evaluation of relative URLs in Git is identical to that of relative directories).

The default remote is the remote of the remote tracking branch of the current branch.
If no such remote tracking branch exists or the HEAD is detached, "origin" is assumed to be the default remote.
If the superproject doesn't have a default remote configured the superproject is its own authoritative upstream and the current. working directory is used instead.

这篇关于指定为相对路径时,不能添加git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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