On Thu Oct 21, 2021 at 4:35 PM PDT, Junio C Hamano wrote: > Matheus Tavares <matheus.bernardino@xxxxxx> writes: > > > On Thu, Oct 21, 2021 at 7:47 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: > >> > >> "brian m. carlson" <sandals@xxxxxxxxxxxxxxxxxxxx> writes: > >> > >> > On 2021-10-21 at 17:25:38, Kalyan Sriram wrote: > >> >> Hello, > >> >> > >> >> I was curious why git-submodule does not have an `rm` command. Currently > >> >> I have to manually delete it from .gitmodules, .git/config, > >> >> .git/modules/, etc. See [0]. > >> >> > > [...] > >> I'd imagine that the happy-case implementation should be fairly > >> straight-forward. You would: > >> > >> - ensure that the submodule is "absorbed" already; > >> > >> - run "git rm -f" the submodule to remove the gitlink from the index > >> and remove the directory from the working tree; and > >> > >> - remove the .gitmodules entry for the submodule. > > > > I think "git rm <submodule>" already does these three steps, doesn't it? Wow, this is a surprise. Looks like this behavior is mentioned in the man page but is not very well known. > So perhaps "git submodule rm" would just become a synonym for "git rm"? > > Thanks. Almost, yeah, but not quite. I ran a couple quick tests to clarify my own understanding of how submodules work, and found that: "git rm" deletes the submodule directory completely and modifies .gitmodules, effectively removing the submodule. However, it leaves the entry in .git/config dangling, which is annoying. "git submodule deinit" (which I didn't know existed until I just read the man page) deletes all contents of submodule directory, but leaves the (empty) submodule directory itself intact. It DOES delete the entry in .git/config, but leaves a dangling entry in .gitmodules, so the next "git submodule update --init --recursive" registers and populates the submodule again. > > Wow, that is a unnerving layering violation, but I suspect it is too > late to fix it. I agree, it's probably too late to change the behavior of "git rm" regarding how it treats submodules. That said, I think the cleanest solution would be to update "git rm" to also remove the dangling .git/config entry. Then, I could make "git submodule rm" a synonym for "git rm" for clarity. This would probably also involve updating documentation in multiple locations to make sure everything is consistent, and verifying "git rm" doesn't leave anything else about the submodule dangling. Please let me know if anyone has a better idea for anything I listed. Thanks for your input so far, Junio, Matheus, and Brian! If no one has any objections, I'll figure out how to make these updates and send a patch along. Thanks! Kalyan