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

git - error after changing submodules URL - fatal: Needed a single revision

我从 github 下载了一个模块。但是我没有使用 github 存储库,而是初始化了自己的存储库,并使用一个 "initial commit".

将所有代码推送到我自己的 bitbucket 远程存储库

但我想使用 github 存储库,这样更容易保持最新状态。所以我打开 .gitmodules 并更改了 repo 的 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

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

解决方法是在文件中添加分支信息.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 年第 2 季度,推出了

git submodule set-branch --branch aBranch -- <submodule_path>)

所以总是先查找主分支,然后在调用

之后用上面的命令添加它
git submodule add <git-url.git> <name-of-module>