【发布时间】:2014-07-16 10:05:14
【问题描述】:
我有一个包含几个子模块的仓库。我想添加一些其他的,对我来说最快的方法是使用.gitmodules(在我看来,这显然应该允许任何类型的子模块管理)。
但是,在编辑此文件并添加子模块时,在 git submodule init 之后不会添加任何内容(修改之前已经存在的子模块除外)。
是否有任何解决方案可以在不经过git submodule add 的情况下添加子模块(即,只需编辑.gitmodules 文件,然后编辑git submodule update --init)?
也就是说,下面的工作流程应该自动添加子模块“foo/bar”:
Add the following to .gitmodules:
[submodule "foo/bar"]
path = foo/bar
url = https://example.com/foo.git
Run the following command after saving:
git submodule init
git submodule update
Expected result:
submodule 'foo/bar' automatically gets added
it is also updated (the update command)
【问题讨论】:
-
当您编写
git submodule add时,只需将新条目添加到 .submodules 文件中,因此您所描述的内容是正确的,它应该适合您。这就是为什么在add之后你必须运行init & update -
不使用
git submodule add导致模块没有为我添加(遗憾)......当你考虑它时,git 能够跟踪大量文件中的数千个修改,但完全在.gitmodules中添加 3 行时丢失了... -
我已经根据您的更新更新了我的答案,除非您知道如何在
.git文件夹下创建模块目录,否则您无法手动执行。 -
执行此命令并查看结果
GIT_TRACE=2 git submodule add git@github.com....
标签: git git-submodules