代码之家  ›  专栏  ›  技术社区  ›  Jordi

Git子模块添加错误

  •  0
  • Jordi  · 技术社区  · 6 年前

    我想在一个新创建的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扩展bug的后续问题,第一次尝试添加子模块时失败,但第二次成功。这些是Git扩展在添加子模块时发出的命令;但是,从命令行发出这些命令时也会出现相同的行为。我不知道这种行为是来自Git(问题是Git扩展发出了错误的命令)还是Git错误。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Nepomuk Pajonk    6 年前

    尝试使用

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

    -b 是简单的分支名称。