【问题标题】:git submodule contents are not cloned along with the base repogit 子模块内容不会与基本 repo 一起克隆
【发布时间】:2013-11-29 06:13:24
【问题描述】:

我创建了一个仓库:

git init --bare myrepo.git

然后在同一台服务器上,为生产创建 repo

cd /home/myuser/public_html
git init
git remote add origin /usr/local/gitroot/myrepo.git
git commit --allow-empty -m "Initial commit"

然后创建子模块

cd subdirectory
git init
git add .
git commit -m "Initial submodule commit"
cd ..
git submodule add /home/myuser/public_html/subdirectory subdirectory
git add .
git commit -m "Initial commit of base files and submodule"
git push origin master

然后在我的本地机器上

git clone --recursive ssh://user@mydomain/path/to/git mygitdirectory

在看起来像一个干净的克隆的结尾,我得到了

fatal: repository '/home/myuser/public_html/subdirectory' does not exist
Clone of '/home/myuser/public_html/subdirectory' into submodule path 'subdirectory' failed

在子目录中尝试 git submodule add 和 git submodule update 会产生相同的结果。我最终得到了所有基本文件,但子目录为空。在服务器上,git log 显示了 base files + submodule 的提交,并且 base 和 submodule 中的 git status 都显示为 clean。

后记

我把所有东西都吹走了,并再次尝试将子模块创建更改为:

git submodule add ./subdirectory ./subdirectory

在服务器上产生了一个.gitmodules

[submodule "subdirectory"]
path = subdirectory
url = ./subdirectory

在本地机器上进行克隆时,当它到达子模块部分时会导致同样的错误。因此,我将 .gitmodules(然后进行了 git 子模块同步)更改为:

[submodule "subdirectory"]
path = subdirectory
url = ssh://user@mydomain/path/to/git

阅读(许多)不同的工作流程建议,我发现自己不确定(a)每个 .gitmodules 的内容应该是什么(我假设服务器是正确的)(b)超级 repo 所在的远程裸 repo 是否推送的服务器应该是唯一的裸仓库,或者子模块是否也需要一个(我假设一旦子模块在超级仓库中提交,将超级仓库推送到裸仓库(原点)也会获取子模块历史记录) ,以及 (c) 本地子模块是否需要定义远程(它似乎没有在服务器上,所以我没有那么本地)

【问题讨论】:

    标签: git-submodules


    【解决方案1】:

    您的本地 git 正在尝试使用您最初克隆子模块的远程 URL 克隆子模块 - 这是服务器上的本地路径,不会存在于您的本地计算机上。

    尝试通过 SSH 克隆子模块,这样它的远程 URL 将在服务器和本地计算机上都有效。

    【讨论】:

    • 我该怎么做?我尝试将 .gitmodules 文件中的 url 更改为 repo url + 子模块的相对路径,然后仅使用 repo url 进行尝试。都失败了。如果需要让 git 子模块更新工作,不仅是为了最初获取文件,而且是为了能够保持同步,对吗?
    • 我将 .gitmodules 中子模块的 url 更改为 ssh url,并进行了 git 子模块同步。现在,当我进行 gitmodule 更新时,我收到的错误不是说没有 repo,而是致命的错误:reference is not a tree
    • 我还没有遇到这个特殊的错误,我会在几个小时后回到家时尝试复制它。
    • 在上面添加了一个附言来详细说明 .gitmodules 的内容以及我尝试过的其他内容
    • @Ayen 确实让它工作了,但目前有点混乱。 Git 似乎不喜欢将空存储库克隆为子模块。稍后我将尝试详细说明我已采取的步骤。
    猜你喜欢
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    相关资源
    最近更新 更多