warning: adding embedded git repository: 仓库名

git add 时报错:

warning: adding embedded git repository: 仓库名
hint: You’ve added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add NeteaseCloudMusicApi
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached NeteaseCloudMusicApi
hint:
hint: See “git help submodule” for more information.

背景原因
使用 git add . 时,出现上述错误。是因为在当前 git 仓库中同时包含有另一个 git 仓库。如当前仓库目录下的子文件夹内又是一个仓库。

解决
通常出现这种情况,往往是因为我们 clone 了相关业务逻辑的仓库,并放在自己的 git 仓库下导致的。

1、删除 .git 文件:找到被嵌套的 git 仓库,并删除 .git 文件。(这个文件默认是隐藏的)
2、删除内嵌的git仓库目录(由于上面问题提交后子文件夹仓库只是一个空目录)

git rm --cached [文件夹名]  (-r文件夹名 -f强制)
# 移除版本控制中的指定文件并需要在工作区中保留该文件
3、重新提交
$ git add [文件夹名]
# 将文件添加到暂存区

$ git commit -m "msg"
# 将暂存区推送到本地仓库

$ git push origin [branch_name]
# 推送到远程主分支上

git rm -r -n --cached 文件/文件夹名称 
 
加上 -n 这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。

//确定后删除
git rm -r --cached 文件/文件夹名称

git commit -m "提交说明"
git push origin master

猜你喜欢

转载自blog.csdn.net/CamilleZJ/article/details/128909540