Git子模块添加错误

Git submodule add error

我想在新创建的 git 存储库中添加子模块,但出现错误。如果我再次执行相同的命令,它就会成功。

C:\>mkdir MyRepo

C:\>cd MyRepo

C:\MyRepo>git init
Initialized empty Git repository in C:/MyRepo/.git/

C:\MyRepo>git submodule add -b refs/heads/master C:\MySubmodulesLibrary\MySubmodule MySubmodule
Cloning into 'C:/MyRepo/MySubmodule'...
done.
fatal: 'origin/refs/heads/master' is not a commit and a branch 'refs/heads/master' cannot be created from it
Unable to checkout submodule 'MySubmodule'

C:\MyRepo>git submodule add -b refs/heads/master C:\MySubmodulesLibrary\MySubmodule MySubmodule
Adding existing repo at 'MySubmodule' to the index
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.

Git版本:2.17.1.windows.1

我想知道我做错了什么,我该怎么做才能使这个操作在我第一次执行时就成功。

*这个问题是 Git 扩展错误的后续问题,在该错误中,您第一次尝试添加子模块失败,但第二次成功。这些是 Git Extensions 在添加子模块时发出的命令;但是,从命令行发出它们时会发生相同的行为。我不知道 Git 是否会出现这种行为(问题是 Git 扩展发出了错误的命令)或者这是一个 Git 错误。

尝试使用

git submodule add -b master C:\MySubmodulesLibrary\MySubmodule MySubmodule

-b 是简单的分支名称。