How do I move an existing Git submodule within a Git repository?
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:  
[submodule ".emacs.d/vimpulse"]  
path = .emacs.d/vimpulse  
url = git://gitorious.org/vimpulse/vimpulse.git
 What do I have to type to move the .emacs.d/vimpulse directory to .emacs.d/vendor/vimpulse without deleting it first (explained here and here) and then re-adding it.  
Does Git really need the whole path in the submodule tag
[submodule ".emacs.d/vimpulse"]
or is it also possible to store just the name of the subproject?
[submodule "vimpulse"]
Note: As mentioned in the comments this answer refers to the steps needed with older versions of git. Git now has native support for moving submodules:
 Since git 1.8.5, git mv old/submod new/submod works as expected and does all the plumbing for you.  You might want to use git 1.9.3 or newer, because it includes fixes for submodule moving.  
It's similar to how you remove a submodule (see How do I remove a submodule?):
.gitmodules and change the path of the submodule appropriately, and put it in the index with git add .gitmodules .  mkdir -p new/parent ).  mv -vi old/parent/submodule new/parent/submodule ).  git add new/parent ).  git rm --cached old/parent/submodule .  .git/modules/old/parent/submodule with all its content to .git/modules/new/parent/submodule .  .git/modules/new/parent/config file, make sure that worktree item points to the new locations, so in this example it should be worktree = ../../../../../new/parent/module .  Typically there should be two more .. then directories in the direct path in that place.   Edit the file new/parent/module/.git , make sure that the path in it points to the correct new location inside the main project .git folder, so in this example gitdir: ../../../.git/modules/new/parent/submodule .  
 git status output looks like this for me afterwards:  
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   .gitmodules
#       renamed:    old/parent/submodule -> new/parent/submodule
#
Finally, commit the changes.
The most modern answer, taken from Valloric's comment above:
git mv old/submod new/submod git status .)  git commit and you're good to go!  Done!
In my case, I wanted to move a submodule from one directory into a subdirectory, eg "AFNetworking" -> "ext/AFNetworking". These are the steps I followed:
[core] worktree line.  Mine changed from ../../../AFNetworking to ../../../../ext/AFNetworking  gitdir .  Mine changed from ../.git/modules/AFNetworking to ../../git/modules/ext/AFNetworking  git add .gitmodules git rm --cached AFNetworking git submodule add -f <url> ext/AFNetworking Finally, I saw in the git status:
matt$ git status
# On branch ios-master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   .gitmodules
#   renamed:    AFNetworking -> ext/AFNetworking
Et voila. The above example doesn't change the directory depth, which makes a big difference to the complexity of the task, and doesn't change the name of the submodule (which may not really be necessary, but I did it to be consistent with what would happen if I added a new module at that path.)
链接地址: http://www.djcxy.com/p/16450.html上一篇: 重命名一个git子模块
