gpt4 book ai didi

git - 为所有 Git 子模块设置分支

转载 作者:太空狗 更新时间:2023-10-29 13:51:34 25 4
gpt4 key购买 nike

是否有命令为所有现有 Git 子模块设置相同的分支名称

git submodule add -b develop *

基本上我需要一种方法来递归地为 .gitmodules 文件中的每个模块设置分支。

最佳答案

Looking for a way to recursive set the branch in the .gitmodules file

使用 Git 2.22(2019 年第二季度,四年后),您将能够使用 git submodule set-branch -b <abranch> ,因为 git submodule学会set-branch允许的子命令 submodule.*.branch要修改的设置。

参见 commit b57e811 , commit c89c494 (2019 年 2 月 8 日),和 commit 7a4bb55 (2019 年 2 月 7 日)作者:Denton Liu ( Denton-L ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 01f8d78 ,2019 年 4 月 25 日)

submodule: teach set-branch subcommand

This teaches git-submodule the set-branch subcommand which allows the branch of a submodule to be set through a porcelain command without having to manually manipulate the .gitmodules file.

在您的情况下,对于所有 子模块,使用 git submodule foreach :

git submodule foreach 'git submodule set-branch --branch aBranch -- ${sm_path}'
git submodule foreach 'git submodule set-branch --default -- ${sm_path}'

(最后一行设置master分支,which is the default)


在 Git 2.22 之前,您将使用我在“How can I specify a branch/tag when adding a Git submodule?”中提到的命令

 git submodule foreach 'git config -f .gitmodules submodule.${sm_path}.branch <branch>'

注意:Git 2.24(2019 年第 4 季度)明确了 --default--branch选项是互斥的。

参见 commit 40e747e (2019 年 9 月 16 日)作者:Denton Liu ( Denton-L ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 7f17913 ,2019 年 10 月 7 日)

关于git - 为所有 Git 子模块设置分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27927023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com