git 删除子模块

For many git-based projects, submodules are useful in avoiding duplicate work and easing utility library updates.  There are times, however, when a submodule needs to be removed from a project.  Submodules aren’t removed with git rm submoduledir, they must be removed in a more tedious, manual fashion.  There are many unclear explanations of how to remove a submodule but I found one on Stack Overflow that’s concise, so I thought I’d share it.  The steps are as follows:

对于许多基于git的项目,子模块可用于避免重复工作并简化实用程序库更新。 但是,有时需要从项目中删除子模块。 不能使用git rm submoduledir删除子模块,而必须以更繁琐,手动的方式删除它们。 关于如何删除子模块有很多不清楚的解释,但是我在Stack Overflow上找到了一个简洁明了的解释,因此我想与大家分享。 步骤如下:

  1. Delete the relevant section from the .gitmodules file.  The section would look similar to:

    .gitmodules文件中删除相关部分。 该部分看起来类似于:

    
    [submodule "vendor"]
    	path = vendor
    	url = git://github.com/some-user/some-repo.git
    
  2. Stage the .gitmodules changes via command line using:git add .gitmodules

    使用以下命令通过命令行git add .gitmodules .gitmodules更改: git add .gitmodules

  3. Delete the relevant section from .git/config, which will look like:

    .git/config删除相关部分,如下所示:

    
    [submodule "vendor"]
    	url = git://github.com/some-user/some-repo.git
    
  4. Run git rm --cached path/to/submodule .  Don’t include a trailing slash — that will lead to an error.

    运行git rm --cached path/to/submodule 。 请勿在结尾加上斜线-否则会导致错误。

  5. Run rm -rf .git/modules/submodule_name

    运行rm -rf .git/modules/submodule_name

  6. Commit the change:

    提交更改:

  7. Delete the now untracked submodule files rm -rf path/to/submodule

    删除现在未跟踪的子模块文件rm -rf path/to/submodule

Those steps will get you rid of that unwanted submodule.  A lot harder than adding one, eh?

这些步骤将使您摆脱不必要的子模块。 比加一个难得多,是吗?

翻译自: https://davidwalsh.name/git-remove-submodule

git 删除子模块