git 子模块更新 --remote 不起作用
git submodule update --remote does not work
我克隆了一个 git 存储库 mainrepo
,它有一个子模块 submodule1
。当我尝试从 submodule1
:
获取最新更新时
$ cd mainrepo
$ git submodule add git@bitbucket.org:myaccount/submodule1.git
$ git submodule update --remote submodule1
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--] [<path>...]
$ git submodule update --remote
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--] [<path>...]
我确定我曾经尝试过以这种方式更新 submodules
,文档也说要这样做,但我不明白为什么它不起作用。
但是如果我直接在 submodule
中进行获取和合并,它会根据需要更新到最新的存储库提交:
$ cd submodule1
$ git fetch && git merge master
为什么 submodule update --remote submodule1
命令不起作用?
也许这会有所帮助:
$ vim mainrepo/.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@bitbucket.org:myaccount/mainrepo.git
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "local/src/utils"]
url = git@bitbucket.org:myaccount/submodule1.git
$ vim .gitmodules
[submodule "submodule1"]
path = submodule1
url = git@bitbucket.org:myaccount/submodule1.git
我建议阅读 git 中关于子模块的速成课程:https://git-scm.com/book/en/v2/Git-Tools-Submodules
我的猜测是,由于您克隆的存储库已经有一个子模块(在存储库的根目录中检查 .gitmodules
!)您不必再次 git submodule add
它。
克隆存储库,然后 运行 git submodule update --recursive
就足够了!
或者,git clone --recurse-submodules
会自动为您执行此操作。
我克隆了一个 git 存储库 mainrepo
,它有一个子模块 submodule1
。当我尝试从 submodule1
:
$ cd mainrepo
$ git submodule add git@bitbucket.org:myaccount/submodule1.git
$ git submodule update --remote submodule1
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--] [<path>...]
$ git submodule update --remote
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--] [<path>...]
我确定我曾经尝试过以这种方式更新 submodules
,文档也说要这样做,但我不明白为什么它不起作用。
但是如果我直接在 submodule
中进行获取和合并,它会根据需要更新到最新的存储库提交:
$ cd submodule1
$ git fetch && git merge master
为什么 submodule update --remote submodule1
命令不起作用?
也许这会有所帮助:
$ vim mainrepo/.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@bitbucket.org:myaccount/mainrepo.git
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "local/src/utils"]
url = git@bitbucket.org:myaccount/submodule1.git
$ vim .gitmodules
[submodule "submodule1"]
path = submodule1
url = git@bitbucket.org:myaccount/submodule1.git
我建议阅读 git 中关于子模块的速成课程:https://git-scm.com/book/en/v2/Git-Tools-Submodules
我的猜测是,由于您克隆的存储库已经有一个子模块(在存储库的根目录中检查 .gitmodules
!)您不必再次 git submodule add
它。
克隆存储库,然后 运行 git submodule update --recursive
就足够了!
或者,git clone --recurse-submodules
会自动为您执行此操作。