0. mv a/submodule a/submodule_tmp
1. git submodule deinit -f -- a/submodule2. rm -rf .git/modules/a/submodule3. git rm -f a/submodule# Note: a/submodule (no trailing slash)
# or, if you want to leave it in your working tree and have done step 03. git rm --cached a/submodule3bis mv a/submodule_tmp a/submodule
# Remove the submodule entry from .git/configgit submodule deinit -f path/to/submodule
# Remove the submodule directory from the superproject's .git/modules directoryrm -rf .git/modules/path/to/submodule
# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodulegit rm -f path/to/submodule
$ git status --porcelainM two$ git submodule deinit twoerror: the following file has local modifications:two(use --cached to keep the file, or -f to force removal)fatal: Submodule work tree 'two' contains local modifications; use '-f' to discard them$ cd two$ git submodule deinit --allerror: the following file has local modifications:md5chk(use --cached to keep the file, or -f to force removal)fatal: Submodule work tree 'md5chk' contains local modifications; use '-f' to discard them$ cd md5chk$ git submodule deinit --allerror: the following file has local modifications:tino(use --cached to keep the file, or -f to force removal)fatal: Submodule work tree 'tino' contains local modifications; use '-f' to discard them$ cd tino$ git status --porcelain?? NEW$ git clean -i -f -dWould remove the following item:NEW*** Commands ***1: clean 2: filter by pattern 3: select by numbers 4: ask each5: quit 6: helpWhat now> 1Removing NEW$ cd ../../..$ git status --porcelain$ git submodule deinit twoCleared directory 'two'Submodule 'someunusedname' (https://github.com/hilbix/src.git) unregistered for path 'two'
mkdir tmptest &&cd tmptest &&git init &&git submodule add https://github.com/hilbix/empty.git two &&git commit -m . &&git submodule deinit two &&git rm two &&git commit -m . &&git submodule add https://github.com/hilbix/src.git two
最后一行输出以下错误:
A git directory for 'two' is found locally with remote(s):origin https://github.com/hilbix/empty.gitIf you want to reuse this local git directory instead of cloning again fromhttps://github.com/hilbix/src.gituse the '--force' option. If the local git directory is not the correct repoor you are unsure what this means choose another name with the '--name' option.