如何添加git子模块并将其标记为发布版本?

6
git clone my-new-repo-url
mkdir deps
cd deps
git submodule add -b 6.2.0 https://github.com/leethomason/tinyxml2.git

产出率
fatal: 'origin/6.2.0' is not a commit and a branch '6.2.0' cannot be created from it
Unable to checkout submodule 'deps/tinyxml2'

不会生成 .gitmodules 文件,但会创建一个文件夹 .git/modules/deps/tinyxml2 并在 deps/tinyxml2 中添加一个仓库。

我之前以为这样做会在 .gitmodules 中生成相应的内容。

[submodule "deps/tinyxml2"]
    path = deps/tinyxml2
    url = https://github.com/leethomason/tinyxml2.git
    branch = 6.2.0

但现在它不起作用了,怎么回事?

1个回答

11

分支和发布标签并不相同。分支可能会继续开发并随时间变化。在 .gitmodules 文件中设置 branch = something 表示子模块将在更新时跟踪该分支。


git submodule add https://github.com/leethomason/tinyxml2.git 命令将在 .gitmodules 文件中添加以下内容:

[submodule "deps/tinyxml2"]
path = deps/tinyxml2
url = https://github.com/leethomason/tinyxml2.git

然后手动检查子模块中所需标签的方法是:

cd deps/tinyxml2
git checkout 6.2.0

使用Add/commit/push命令

git commit -am "adding and commiting all in one command"
git push

将子模块添加到仓库中,然后在浏览器中我们可以看到:enter image description here,其中是生成该发布标签的特定提交。
现在在另一个文件夹中进行全新的克隆。
git clone my-new-repo-url
git submodule update --init --recursive

子模块是否已经检出相同的发布标签6.2.0(提交c1424ee4


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接