问题

执行git add .报错:

warning: 正在添加嵌入式 git 仓库:reference/esp-qcloud
提示:You've added another git repository inside your current repository.
提示:Clones of the outer repository will not contain the contents of
提示:the embedded repository and will not know how to obtain it.
提示:If you meant to add a submodule, use:
提示:
提示:	git submodule add <url> reference/esp-qcloud
提示:
提示:If you added this path by mistake, you can remove it from the
提示:index with:
提示:
提示:	git rm --cached reference/esp-qcloud
提示:
提示:See "git help submodule" for more information.

解决

1、添加子模块

执行以下命令,project为你报错的仓库,<url>为该仓库的地址。

#=删除仓库索引=======================================
# 如果是文件
git rm --cached reference/esp-qcloud
# 如果是文件夹
git rm -r --cached reference/esp-qcloud
# 如果执行以上命令后提示:【 error: 如下文件其暂存的内容和工作区及 HEAD 中的都不一样:】 ,`-f`强制删除
git rm -r -f --cached reference/esp-qcloud

#=添加仓库索引=======================================
# 创建子模块并添加 url 地址
git submodule add <url> project
# 例如:
git submodule add https://gitee.com/JavonPeng/project.git reference/esp-qcloud
# 或者使用 ssh 地址
git submodule add git@gitee.com:JavonPeng/project.git reference/esp-qcloud

添加成功后会生成.gitmodules文件,即添加子模块:

[submodule "reference/esp-qcloud"]	# 子仓库名
	path = reference/esp-qcloud		# 子仓库路径
	url = https://gitee.com/JavonPeng/esp-qcloud.git	# 子仓库地址

2、提交:

git add .
git commit -m "update reference/esp-qcloud"
git push
  • push后在远程仓库对应的文件夹后面有@+数字,@后面的数字是哈希值,用于确定唯一的提交状态。
  • 这即是子模块,点击可跳转到对应仓库。
    在这里插入图片描述

3、拉取或者更新子模块:

git submodule update --init --recursive
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐