Suppose that a .gitmodules
file includes the following lines
[submodule "sub/x"]
path = sub/x
...which resulted from a command of the form
git submodule add $url sub/x
After the fact (and after having added several commits, both to the superproject as well as the submodule), I realize that I should have run this instead:
git submodule add --name x $url sub/x
...so that the two lines in the .gitmodules
file corresponding to the two quoted earlier would have been
[submodule "x"]
path = sub/x
I want to fix the superproject so that the name of the submodule is x
rather than sub/x
, but the path remains sub/x
1.
My immediate interest is in learning how to fix the history (e.g. through an interactive rebase) of the superproject, so that in the end the repo looks as if the second git submodule add
command was the one used from the beginning. (FWIW, this repo has not yet been published, though I do intend to do so.) For future reference, however, I am also interested in learning how to do this without modifying the history, i.e. by adding one or more new commits to it.
I have tried to remove the submodule and add it again (based on the git submodule deinit
recipe given here), but I quickly find myself in a mess. (I think that part of the problem is that, as I already mentioned, I have added several commits to the submodule, made corresponding updates to the superproject's submodule information, along the way.)
Therefore, I am hoping to find more direct guidance on how to do this renaming.
1 There is an earlier post whose title suggests that it is asking exactly the question I am asking here, but in fact that post is asking for not only how to rename the submodule, but also how to change its path. It turns out that most of the content in the answers to that question focus on the problem of changing the module's path.