git 将子模块添加到现有目录

标签 git clone git-submodules git-clone

我在父文件夹中有一个 git 存储库。让我们将此文件夹称为“根”。
然后文件夹中有一个子目录,我们称之为“子”。我想要做的是将远程存储库作为子模块克隆到“子”中:

git submodule add git@github.com:username/repopath child/
git submodule add git@github.com:username/repopath ./child/

以上都给了我错误:

child already exists in the index



我尝试从被跟踪中删除目录:
git rm --cached .\child\*
git submodule add git@github.com:username/repopath child/

然后我得到这个错误:

'child' already exists and is not a valid git repo



非常感激任何的帮助

谢谢

最佳答案

首先,在新的克隆中尝试您的 submodule add 命令,因为您之前的尝试可能为子模块留下了部分状态。

二、先试试

git rm -r --cached child

然后,添加并提交。

最后,试试你的 git submodule command :
git submodule add -- git@github.com:username/repopath child

添加并提交。

关于git 将子模块添加到现有目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42096543/

相关文章:

javascript - JQuery 淡入淡出悬停效果 - 帮助?

javascript - Coffeescript/Javascript 为什么,克隆数组中的对象在传递给方法时似乎丢失了它们的引用?

git - 如何处理转换为 Mercurial 的仓库中的 Git 子模块

git - 如何在文件夹层次结构中将所有 git 内容向上移动一级?

git - .gitignore - 忽略目标文件夹中除 1 个 JAR 文件之外的所有文件

git - CircleCI 忽略 git 标签过滤器

java - 当我修改 BeanUtils.CopyProperties 的目标对象时,源代码被修改

git - 如何查看 git 子模块指向哪个提交

git submodule update --init 安装 dot-emacs 文件时出错

Git:将分支 merge 到主存储库作为新分支