使用 git 个子模块进行可重现的构建(依赖管理)?
Use git submodules for reproducible builds (dependency management)?
我正在尝试想出一种方法来处理 Git 项目依赖项,例如 Swift 包管理器。
我想具体说明一下,假设我的应用程序版本 1.2 依赖于框架 A,版本 1.0。
然后当我检查我的应用程序的 v1.2 时,框架代码应该自动拉入标签 v1.0。
code/myapp/ tag v1.2
lib/frameworkA tag v1.0
我尝试了 Git 个子模块,但我无法找到一种方法来在我签出父应用程序的特定标签时自动签出特定的子模块标签。
.gitmodules 文件作为父项目的一部分签入。理想情况下,它将包含有关要使用子模块的哪个标签的详细信息。这可能吗?如果没有,是否有另一种不使用子模块的方法?
默认情况下,git-checkout
不更新子模块。
但是,从 Git 2.14 开始,您可以通过将 submodule.recurse
配置选项设置为 true
:
来更改此行为
submodule.recurse
Specifies if commands recurse into submodules by default. This applies to all commands that have a --recurse-submodules
option, except clone
. Defaults to false.
从 Git 2.13 开始,git-checkout
获得了 --recurse-submodules
选项,所以您需要做的就是:
git config --global submodule.recurse true
和 Git 将自动 运行 git submodule update --recursive
每当您切换到不同的分支时。
至于将子模块与特定标签相关联,您可以通过在子模块目录中手动签出标签来完成:
cd path/to/submodule
git checkout <submodule-tag-name>
此时,子模块将指向 <tag-name>
引用的提交。然后,您所要做的就是将修改后的子模块告诉父项目:
cd path/to/parent/project
git add path/to/submodule
git commit -m "Sets submodule to tag <submodule-tag-name>"
git tag -a <parent-tag-name>
从现在开始,每当您在父项目中签出 <parent-tag-name>
时,Git 将自动签出子模块中与 <submodule-tag-name>
关联的提交。
我正在尝试想出一种方法来处理 Git 项目依赖项,例如 Swift 包管理器。
我想具体说明一下,假设我的应用程序版本 1.2 依赖于框架 A,版本 1.0。
然后当我检查我的应用程序的 v1.2 时,框架代码应该自动拉入标签 v1.0。
code/myapp/ tag v1.2
lib/frameworkA tag v1.0
我尝试了 Git 个子模块,但我无法找到一种方法来在我签出父应用程序的特定标签时自动签出特定的子模块标签。
.gitmodules 文件作为父项目的一部分签入。理想情况下,它将包含有关要使用子模块的哪个标签的详细信息。这可能吗?如果没有,是否有另一种不使用子模块的方法?
默认情况下,git-checkout
不更新子模块。
但是,从 Git 2.14 开始,您可以通过将 submodule.recurse
配置选项设置为 true
:
submodule.recurse
Specifies if commands recurse into submodules by default. This applies to all commands that have a--recurse-submodules
option, exceptclone
. Defaults to false.
从 Git 2.13 开始,git-checkout
获得了 --recurse-submodules
选项,所以您需要做的就是:
git config --global submodule.recurse true
和 Git 将自动 运行 git submodule update --recursive
每当您切换到不同的分支时。
至于将子模块与特定标签相关联,您可以通过在子模块目录中手动签出标签来完成:
cd path/to/submodule
git checkout <submodule-tag-name>
此时,子模块将指向 <tag-name>
引用的提交。然后,您所要做的就是将修改后的子模块告诉父项目:
cd path/to/parent/project
git add path/to/submodule
git commit -m "Sets submodule to tag <submodule-tag-name>"
git tag -a <parent-tag-name>
从现在开始,每当您在父项目中签出 <parent-tag-name>
时,Git 将自动签出子模块中与 <submodule-tag-name>
关联的提交。