为什么执行 git rm -rf 命令无法删除包含子模块的文件夹?

4

当我执行git status时,我看到的是:

$ git status
# On branch master
# Your branch is ahead of 'github/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   octopress (modified content, untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

当我执行git rm -rf octopress命令时,会看到以下信息:
$ git rm -rf octopress
error: submodule 'octopress' (or one of its nested submodules) uses a .git directory
(use 'rm -rf' if you really want to remove it including all of its history)

您对此有何看法?

2个回答

5
这条错误信息让我也感到困惑,但它的意思是你应该使用rm -rf不是git rm -rf
(use 'rm -rf' if you really want to remove it including all of its history)

因此,您应该能够做到这一点:

$ rm -rf octopress
$ git rm octopress

0
如果你只是想从 git status 中获得干净的输出,你可以简单地:
git status --ignore-submodules

否则,您需要明确处理子模块。在我们处理子模块之前,请注意 git 子模块不应该有 .git 目录1。您可能正在使用旧版本的 git?
继续。Git 告诉您 octopress 子模块是什么,
#   modified:   octopress (modified content, untracked content)

要解决此问题,您需要进入octopress子模块,并执行以下操作:

  • 重置或提交修改的内容
  • 提交、删除或.gitignore未跟踪的内容

或者,如您在问题中所建议的那样,使用更大的力量,移除子模块的本地检出即可。

$ git submodule deinit --force octopress

适用于 git 1.8.3 及以上版本

当指定 --force 时,即使子模块包含本地修改,其工作树也将被删除。

接下来使用 git rm octopress 从仓库中移除子模块。


1 看看这个补丁,

将子模块的git-dir移动到超级项目的$GIT_DIR/modules/[name_of_submodule]中。 这是迈向能够删除子模块目录而不会丢失其.git目录信息的一步,因为现在该信息存储在子模块工作树之外。
http://git.661346.n2.nabble.com/PATCH-v5-0-2-submodule-move-gitdir-into-superproject-td6692559.html


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接