要解决Git提示的嵌套仓库问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 <url> themes/butterfly
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached themes/butterfly
hint:
hint: See "git help submodule" for more information.
hint: Disable this message with "git config advice.addEmbeddedRepo false"

请根据实际需求选择以下两种方案之一

方案一:将目录转为子模块(推荐,若需独立管理)

1
2
3
4
5
6
7
8
# 1. 删除当前目录的Git信息(若已错误添加)
git rm --cached themes/butterfly

# 2. 添加为子模块(替换<url>为实际仓库地址)
git submodule add <url> themes/butterfly

# 3. 提交子模块配置
git commit -m "Add themes/butterfly as submodule"

方案二:移除嵌套仓库(若需合并内容)

1
2
3
4
5
6
7
8
9
10
11
# 1. 删除子目录的Git信息(保留文件内容)
rm -rf themes/butterfly/.git

# 2. 从Git索引中移除该目录
git rm --cached themes/butterfly

# 3. 重新添加目录内容到主仓库
git add themes/butterfly

# 4. 提交更改
git commit -m "Remove nested repo and integrate files"

操作说明:

  1. 子模块方案适用于需要独立跟踪该目录版本的情况(如主题库需单独更新)。
  2. 移除方案适用于直接合并代码到主仓库的场景(如静态资源目录)。
  3. 执行后请验证:git status应不再显示嵌套仓库警告。

附加提示:

  • 查看子模块帮助:git help submodule
  • 禁用该警告(不推荐):git config advice.addEmbeddedRepo false