Rename a git submodule

前端 未结 7 2130
-上瘾入骨i
-上瘾入骨i 2020-12-04 05:32

Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name).

<
相关标签:
7条回答
  • 2020-12-04 06:14

    The correct solution is:

    mv oldpath ~/another-location
    git rm oldpath
    git submodule add submodule-repository-URL newpath
    

    Source: Rename git submodule

    0 讨论(0)
  • 2020-12-04 06:18

    I found following workflow working:

    • Update .gitmodules
    • mv oldpath newpath
    • git rm oldpath
    • git add newpath
    • git submodule sync

    Note: this approach does not update the index and .gitmodules properly in 2018 versions of GIT.

    Note: You may be able to now just do git mv oldpath newpath now, as pointed out in VonC's answer. (Ensure you are using the latest version of git)

    0 讨论(0)
  • 2020-12-04 06:21

    Edit the .gitmodules file to rename the submodule and then rename the submodule directory.

    I think you might need to do a git submodule sync afterwards, but I'm not in a position to check right now.

    0 讨论(0)
  • 2020-12-04 06:22

    MacOs: When I wanna use VonC solution to change submodule folder Common to lowercase:

    git mv Common common
    

    I get

    fatal: renaming 'Common' failed: Invalid argument

    Solution - use some temporary folder name and move twice:

    git mv Common commontemp
    git mv commontemp common
    

    That's all :)

    0 讨论(0)
  • 2020-12-04 06:33

    It's not possible to rename it, so you've to remove it first (deinit) and add it again.

    So after removing it:

    git submodule deinit <path>
    git rm --cached <path>
    

    you may also double check and remove the references to it in:

    • .gitmodules
    • .git/config
    • remove reference folder from .git/modules/<name> (best to make a backup), as each folder has config file where it keeps the reference to its worktree

    then stage your changes by committing any changes to your repo by:

    git commit -am 'Removing submodule.'
    

    and double check if you don't have any outstanding issues by:

    git submodule update
    git submodule sync
    git submodule status
    

    so now you can add the git submodule again:

    git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
    
    0 讨论(0)
  • 2020-12-04 06:34

    I just tried a few of the suggested above. I'm running:

    $ git --version
    git version 1.8.4
    

    I found it was best to de-init the submodule, remove the directory and create a new submodule.

    git submodule deinit <submodule name>
    
    git rm <submodule folder name>
    
    git submodule add <address to remote git repo> <new folder name>
    

    At least that is what worked for me best. YMMV!

    0 讨论(0)
提交回复
热议问题