How do I move an existing Git submodule within a Git repository?

后端 未结 10 629
面向向阳花
面向向阳花 2020-11-29 14:39

I would like to change the directory name of a Git submodule in my Git superproject.

Lets suppose I have the following entry in my .gitmodules file:

10条回答
  •  有刺的猬
    2020-11-29 14:52

    [Update: 2014-11-26] As Yar summarizes nicely below, before you do anything, make sure you know the URL of the submodule. If unknown, open .git/.gitmodules and examine the keysubmodule..url.

    What worked for me was to remove the old submodule using git submodule deinit followed by git rm . Then add the submodule again with the new folder name and commit. Checking git status before committing shows the old submodule renamed to the new name and .gitmodule modified.

    $ git submodule deinit foo
    $ git rm foo
    $ git submodule add https://bar.com/foo.git new-foo
    $ git status
    renamed:    foo -> new-foo
    modified:   .gitmodules
    $ git commit -am "rename foo submodule to new-foo"
    

提交回复
热议问题