threads / discuss / 20057

git submodule remove?

Subject: git submodule remove?

## tl;dr

3 messages between Jul 8, 2009 and Jul 11, 2009.

replies: 2people: 3as markdown or json

Tim Henigan· Jul 8, 2009, 19:41 UTC · lore
Hello,

I recently encountered a situation where a user wanted to remove a submodule from a repository. Searching the mail archive, I found this thread [1], but it does not appear that it was ever followed up.

The Git Submodule Tutorial [2] has instructions for removing submodules, but it seems natural to teach git how to "submodule rm".

This change would require git-submodule.sh to:
    1. Modify the .gitmodules file (remove the entry for the submodule).
    2. Modify the .git/config file (remove the entry for the submodule).
    3. Delete the newly untracked files.

Another option to consider would be a "submodule rm --cached" option which would keep the newly untracked files. However, with this option, I believe it should still descend into the submodule directory to remove the leftover submodule ".git" folder.

Is there another way of doing this? If not, does this sound like a reasonable change?

Thanks, Tim Henigan

[1] http://article.gmane.org/gmane.comp.version-control.git/101610/match=submodule+remove [2] http://git.or.cz/gitwiki/GitSubmoduleTutorial

Raman Gupta· Jul 8, 2009, 21:54 UTC · re: Tim Henigan · lore

Re: git submodule remove?

Tim Henigan wrote:
> The Git Submodule Tutorial [2] has instructions for removing submodules, but it
> seems natural to teach git how to "submodule rm".
I'd like to see this as well.
> This change would require git-submodule.sh to:
>     1. Modify the .gitmodules file (remove the entry for the submodule).
>     2. Modify the .git/config file (remove the entry for the submodule).
>     3. Delete the newly untracked files.

I'm not sure it should be removed from .git/config, and the untracked files, automatically. If the module is only being removed on one branch, then switching back to another branch will require the module to be initialized again. Of course, then the user has to deal with untracked files and to remember to prune entries from .git/config once no more branches refer to them.

This is also a problem when renaming modules -- I always end up having at least two entries in .git/config -- one for the branches using the old name and one for the branches using the new name.

Perhaps one way to refactor submodule support in .git/config would be to allow .git/config to specify search/replace expressions (simple or regex-based) that would apply to the entries in .gitmodules. Most of the time, a few simple expressions should be sufficient to cover all of the necessary local settings.

Another possible useful change/addition would be to move the submodule files in and out of the superproject (perhaps to/from a holding area in superproject/.git) as the user switches their working copy between branches that contain or do not contain specific submodules.

Cheers, Raman Gupta

Tim Harper· Jul 11, 2009, 05:27 UTC · re: Tim Henigan · lore

Re: git submodule remove?

On Wed, Jul 8, 2009 at 1:41 PM, Tim Henigan<tim.henigan@gmail.com> wrote:
Show 15 quoted lines
> Hello,
>
> I recently encountered a situation where a user wanted to remove a submodule
> from a repository.  Searching the mail archive, I found this thread
> [1], but it does
> not appear that it was ever followed up.
>
> The Git Submodule Tutorial [2] has instructions for removing submodules, but it
> seems natural to teach git how to "submodule rm".
>
> This change would require git-submodule.sh to:
>    1. Modify the .gitmodules file (remove the entry for the submodule).
>    2. Modify the .git/config file (remove the entry for the submodule).
>    3. Delete the newly untracked files.
>

Submodules are tracked by the tree. You'll need to 'rm -rf' the submodule, and then 'git rm' the folder to remove it.

Show 8 quoted lines
> Another option to consider would be a "submodule rm --cached" option which would
> keep the newly untracked files.  However, with this option, I believe
> it should still
> descend into the submodule directory to remove the leftover submodule
> ".git" folder.
>
> Is there another way of doing this?  If not, does this sound like a
> reasonable change?

I can think of the only opposition being how blatantly dangerous it would be. You're creating a command that will nuke the whole repository, along with any unpushed changes. There's potential there for someone to seriously injure themselves without realizing it.

There's also the issue of once you delete a submodule... now what? Git won't automatically remove them from other repositories when the change gets pulled. The folder will show up as untracked. So far the current paradigm with git submodules is git is very "hands off" and leaves as much as possible to you. I think we would have to see a change in thought consistently around how to approach submodules before git implements anything of this sort.

← back to recent threads