为什么GitRM-rf不能去掉一个包含子模块的文件夹?

为什么GitRM-rf不能去掉一个包含子模块的文件夹?,git,Git,当我执行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

当我执行
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
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)

想法?

如果您显然想要从git status获得一个干净的输出,您可以

git status --ignore-submodules
否则,您将需要显式地处理子模块。在处理子模块之前,请注意git子模块不应该有
.git
directory1。您可能正在使用git的旧版本吗

继续。Git告诉您,对于
octopress
子模块

#   modified:   octopress (modified content, untracked content)
要解决此问题,您需要进入
octopress
子模块

  • 重置或提交修改的内容
  • 提交、删除或
    .gitignore
    未跟踪的内容
或者,使用一个更大的锤子,正如您在问题中所建议的,您可以移除子模块的本地签出

$ git submodule deinit --force octopress
适用于git 1.8.3及以后版本

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

然后按git rm octopress从回购中删除子模块


看这个补丁

将子模块的git dir移动到的$git_dir/modules/[name_of_submodule] 超级项目。这是能够删除子模块的一个步骤 目录,而不会丢失其.git目录中的信息 因为它现在存储在子模块工作树之外。


这个错误消息也让我感到困惑,但它想说的是您应该使用
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