我正在尝试将子模块放入repo。问题是当我克隆父repo时,子模块文件夹完全是空的。
有没有办法让git clone parent_repo
实际将数据放入子模块文件夹?
例如,http://github.com/cwolves/sequelize/tree/master/lib/,nodejs-mysql-native
指向外部git子模块,但当我签出sequelize
项目时,该文件夹为空。
答案 0 :(得分:2681)
使用Git及更高版本的2.13版本,可以使用--recurse-submodules
代替--recursive
:
git clone --recurse-submodules -j8 git://github.com/foo/bar.git
cd bar
编者注:-j8
是可选的性能优化,可在2.8版本中使用,并且一次最多可同时获取8个子模块 - 请参阅man git-clone
。 < / p>
使用版本1.9的Git直到版本2.12(-j
标志仅在版本2.8 +中可用):
git clone --recursive -j8 git://github.com/foo/bar.git
cd bar
使用Git及更高版本的1.6.5版,您可以使用:
git clone --recursive git://github.com/foo/bar.git
cd bar
对于已克隆的repos或较旧的Git版本,请使用:
git clone git://github.com/foo/bar.git
cd bar
git submodule update --init --recursive
答案 1 :(得分:430)
在填充子模块之前,您必须做两件事:
git submodule init
git submodule update
答案 2 :(得分:162)
原始答案2010
在评论中提及joschi时, git submodule
现在支持--recursive
选项(Git1.6.5及更多版本)。
如果指定了
--recursive
,则此命令将递归到已注册的子模块中,并更新其中的任何嵌套子模块。
有关初始部分,请参阅Working with git submodules recursively
有关详情,请参阅 git submodule
explained 。
对于git及更高版本的1.6.5版,您可以使用
–-recursive
选项克隆超级项目来自动执行此操作:
git clone --recursive git://github.com/mysociety/whatdotheyknow.git
使用git 2.8更新2016:请参阅“How to speed up / parallelize downloads of git submodules using git clone --recursive
?”
您可以并行使用多个线程启动子模块 例如:
git fetch --recurse-submodules -j2
答案 3 :(得分:55)
您可以使用此命令克隆包含所有子模块的repo:
git clone --recursive YOUR-GIT-REPO-URL
或者,如果您已经克隆了项目,则可以使用:
git submodule init
git submodule update
答案 4 :(得分:30)
如果您的子模块已添加到分支中,请务必将其包含在克隆命令中...
git clone -b <branch_name> --recursive <remote> <directory>
答案 5 :(得分:26)
试试这个:
git clone --recurse-submodules
假设您已将子模块添加到父项目中,它会自动提取子模块数据。
答案 6 :(得分:19)
迟到的回答
// git CLONE INCLUDE-SUBMODULES ADDRESS DESTINATION-DIRECTORY
git clone --recursive https://USERNAME@bitbucket.org/USERNAME/REPO.git DESTINATION_DIR
因为我花了整整一个小时与朋友一起摆弄:即使你拥有BitBucket的管理员权限,也要克隆ORIGINAL存储库并使用拥有repo的人的密码。很恼火,发现你遇到了这个地雷:P
答案 7 :(得分:17)
尝试将此子模块包含在git存储库中。
git clone -b <branch_name> --recursive <remote> <directory>
或强>
git clone --recurse-submodules
答案 8 :(得分:17)
我认为您可以执行3个步骤:
git clone
git submodule init
git submodule update
答案 9 :(得分:14)
克隆存储库时,可以使用--recursive
标志。此参数强制git克隆存储库中所有已定义的子模块。
git clone --recursive git@repo.org:your_repo.git
克隆后,有时可能会更改子模块分支,因此请在其后运行以下命令:
git submodule foreach "git checkout master"
答案 10 :(得分:10)
子模块并行提取旨在通过一次启用多个存储库的获取来减少获取存储库及其所有相关子模块所需的时间。这可以通过使用新的--jobs选项来完成,例如:
git fetch --recurse-submodules --jobs=4
根据Git团队的说法,这可以大大加快更新包含许多子模块的存储库。当使用--recurse-submodules而没有新的--jobs选项时,Git将逐个获取子模块。
答案 11 :(得分:7)
我对GitHub存储库有同样的问题。我的帐户缺少SSH密钥。这个过程是
然后,您可以使用子模块(git clone --recursive YOUR-GIT-REPO-URL
)克隆存储库
或
运行git submodule init
和git submodule update
以在已克隆的存储库中获取子模块。
答案 12 :(得分:5)
使用此命令克隆所有子模块的 repo
git clone --recurse-submodules git@gitlab.staging-host.com:yourproject
更新所有子模块的代码
git submodule update --recursive --remote
答案 13 :(得分:5)
如果这是一个新项目,只需执行以下操作即可:
$ git clone --recurse-submodules https://github.com/chaconinc/YourProjectName
如果已安装,则比:
$ cd YourProjectName (for the cases you are not at right directory)
$ git submodule init
$ git submodule update
答案 14 :(得分:4)
试试这个。
git clone -b <branch_name> --recursive <remote> <directory>
如果您已在分支中添加了子模块,请确保将其添加到克隆命令中。
答案 15 :(得分:4)
克隆父仓库(包含一些子模块仓库)后,请执行以下操作:
git submodule update --init --recursive
答案 16 :(得分:2)
只需在您的项目目录中执行这些操作即可。
$ git submodule init
$ git submodule update
答案 17 :(得分:0)
git submodule foreach git pull origin master