我想在我的Git超级项目中更改一个Git子模块的目录名称。
让我们假设我的.gitmodules文件中有以下条目:
[submodule ".emacs.d/vimpulse"]
path = .emacs.d/vimpulse
url = git://gitorious.org/vimpulse/vimpulse.git
我必须输入什么来移动。emacs。D /vimpulse目录到。emacs。D /vendor/vimpulse而不首先删除它(解释
这里和这里),然后重新添加。
Git真的需要子模块标签中的整个路径吗
[submodule ".emacs.d/vimpulse"]
或者也可以只存储子项目的名称?
[submodule "vimpulse"]
更新版本的git
Git现在支持移动子模块:
从git 1.8.5开始,git mv old/submod new/submod就像预期的那样工作,并为你做了所有的管道工作。您可能希望使用git 1.9.3或更新版本,因为它包含了针对子模块移动的修复。
git的旧版本
正如评论中提到的,这个答案指的是旧版本git所需的步骤。
这个过程类似于如何删除子模块(参见如何删除子模块?):
Edit .gitmodules and change the path of the submodule appropriately, and put it in the index with git add .gitmodules.
If needed, create the parent directory of the new location of the submodule (mkdir -p new/parent).
Move all content from the old to the new directory (mv -vi old/parent/submodule new/parent/submodule).
Make sure Git tracks this directory (git add new/parent).
Remove the old directory with git rm --cached old/parent/submodule.
Move the directory .git/modules/old/parent/submodule with all its content to .git/modules/new/parent/submodule.
Edit the .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 .. than 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.
更新版本的git
Git现在支持移动子模块:
从git 1.8.5开始,git mv old/submod new/submod就像预期的那样工作,并为你做了所有的管道工作。您可能希望使用git 1.9.3或更新版本,因为它包含了针对子模块移动的修复。
git的旧版本
正如评论中提到的,这个答案指的是旧版本git所需的步骤。
这个过程类似于如何删除子模块(参见如何删除子模块?):
Edit .gitmodules and change the path of the submodule appropriately, and put it in the index with git add .gitmodules.
If needed, create the parent directory of the new location of the submodule (mkdir -p new/parent).
Move all content from the old to the new directory (mv -vi old/parent/submodule new/parent/submodule).
Make sure Git tracks this directory (git add new/parent).
Remove the old directory with git rm --cached old/parent/submodule.
Move the directory .git/modules/old/parent/submodule with all its content to .git/modules/new/parent/submodule.
Edit the .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 .. than 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.
给出的解决方案对我不起作用,然而一个类似的版本却起作用了。
这是一个克隆的存储库,因此子模块git repos包含在顶级存储库.git目录中。所有阳离子都来自顶部存储库:
编辑.gitmodules并更改相关子模块的"path ="设置。(不需要更改标签,也不需要将该文件添加到索引。)
编辑.git/modules/name/config,修改子模块的"worktree ="设置
运行:
Mv submodule newpath/submodule
Git add -u
Git增加了新路径/子模块
我想知道如果存储库是原子的,还是相对的子模块,在我的情况下,它是相对的(submodule/。Git是一个指向topproject/.git/modules/submodule的引用)