git-更改子模块后出错URL-致命:需要单个修订版

问题描述 投票:0回答:1

我从github下载了一个模块。但是,我没有使用github存储库,而是初始化了自己的存储库,并通过一个“初始提交”将所有代码推送到了自己的bitbucket远程存储库。

但是我想使用github仓库,这样更容易保持最新。因此,我打开了.gitmodules并更改了存储库的URL,进行了提交并推送。

但是如果我先执行git clone myrepo_url.git然后执行git submodule --init --update --remote,那么一切都很好,但是我更改了URL的模块。

> fatal: Needed a single revision, unable to find commit of
> origin/master in Submodul-path 'app/code/EthanYehuda/CronjobManager'

那可能是因为我的旧存储库使用master作为主要分支,而github存储库使用了1.x

。git / modules / app / code / EthanYehuda / CronjobManager / config

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        worktree = ../../../../../../app/code/EthanYehuda/CronjobManager
[remote "origin"]
        url = https://github.com/Ethan3600/magento2-CronjobManager.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "1.x"]
        remote = origin
        merge = refs/heads/1.x

。gitmodules

[submodule "app/code/EthanYehuda/CronjobManager"]
        path = app/code/EthanYehuda/CronjobManager
        url = https://github.com/Ethan3600/magento2-CronjobManager.git

如何解决此问题,以便在克隆项目时不显示错误?

git git-submodules
1个回答
0
投票

解决方案是将分支信息添加到文件。gitmodule

[submodule "app/code/EthanYehuda/CronjobManager"]
        path = app/code/EthanYehuda/CronjobManager
        url = https://github.com/Ethan3600/magento2-CronjobManager.git
        branch = 1.x

现在没有错误

((Git 2.22,2019年第二季度,已引入git submodule set-branch --branch aBranch -- <submodule_path>

所以总是先查找主分支,并在调用后用上述命令将其添加

git submodule set-branch --branch aBranch -- <submodule_path>
© www.soinside.com 2019 - 2024. All rights reserved.