【发布时间】:2015-12-22 22:08:20
【问题描述】:
问题
如何将现有的子存储库添加为 git 中的子模块?
为什么
我有一个私有的codespace 超级模块,子模块随机分布:
codespace (git repo, private)
├── Archived_projects (git repos)
└── Projects
├── project-foo (git repo)
└── project-bar (git repo)
有时子模块的提交尚未准备好推送。但我希望在推送超级模块codespace 时保存它们。codespace 是克隆到c9.io 工作区或其他地方的存储库。
我做什么
linus@machine /cygdrive/f/__Storage__/Workspace
$ git clone https://github.com/octocat/Spoon-Knife.git
Cloning into 'Spoon-Knife'...
$ cd Spoon-Knife/
$ git clone https://github.com/octocat/Spoon-Knife.git ./foo/bar
Cloning into './foo/bar'...
$ git add .
来自 cmd.exe
> git submodule add https://github.com/octocat/Spoon-Knife.git ./foo/bar
'foo/bar' already exists in the index
> cat .gitmodules
cat: .gitmodules: No such file or directory
来自 cygwin.exe (bash)
$ git submodule add https://github.com/octocat/Spoon-Knife.git ./foo/bar
': not a valid identifier/Git/mingw64/bin/gettext.sh: line 89: export: `sm_path
'' already exists in the index
$ cat .gitmodules
cat: .gitmodules: No such file or directory
参考
git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>]
[--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
<repository> is the URL of the new submodule’s origin repository.
<path> is the relative location for the cloned submodule to exist in the superproject. If <path> does not exist, then the
submodule is created by cloning from the named URL. If <path> does exist and is already a valid Git repository, then this is
added to the changeset without cloning. This second form is provided to ease creating a new submodule from scratch, and
presumes the user will later push the submodule to the given URL.
In either case, the given URL is recorded into .gitmodules for use by subsequent users cloning the superproject. If the URL
is given relative to the superproject’s repository, the presumption is the superproject and submodule repositories will be
kept together in the same relative location, and only the superproject’s URL needs to be provided: git-submodule will
correctly locate the submodule using the relative URL in .gitmodules.
如果 <path> 确实存在并且已经是一个有效的 Git 存储库,则将其添加到变更集中而不进行克隆。
为什么这在我的情况下不起作用?
【问题讨论】:
-
This might help。将 repo 从工作树中移出,添加子模块,修复 url
标签: git git-submodules cloud9-ide