我想在我的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"]

当前回答

我昨天刚刚经历了这个考验,这个答案非常有效。为了清晰起见,以下是我的步骤:

确保子模块被签入并推入到它的服务器。你还需要知道它在哪个分支上。 您需要子模块的URL !使用更多的.gitmodules,因为一旦你删除了子模块,它就不存在了 现在你可以使用deinit, rm和submodule add

例子

Git子模块在:Classes/lib/mustIReally 移动到:lib/AudioBus URL: http://developer.audiob.us/download/SDK.git

命令

    git submodule deinit Classes/lib/mustIReally
    git rm foo
    git submodule add http://developer.audiob.us/download/SDK.git lib/AudioBus

    # do your normal commit and push
    git commit -a 

注意:git mv不这样做。在所有。

其他回答

在我的例子中,我想将一个子模块从一个目录移动到另一个子目录,例如:"AFNetworking" -> "ext/AFNetworking"以下是我遵循的步骤:

Edit .gitmodules changing submodule name and path to be "ext/AFNetworking" Move submodule's git directory from ".git/modules/AFNetworking" to ".git/modules/ext/AFNetworking" Move library from "AFNetworking" to "ext/AFNetworking" Edit ".git/modules/ext/AFNetworking/config" and fix the [core] worktree line. Mine changed from ../../../AFNetworking to ../../../../ext/AFNetworking Edit "ext/AFNetworking/.git" and fix 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

最后,我在git状态中看到:

matt$ git status
# On branch ios-master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   .gitmodules
#   renamed:    AFNetworking -> ext/AFNetworking

瞧。上面的例子没有改变目录深度,这对任务的复杂性有很大影响,也没有改变子模块的名称(这可能真的没有必要,但我这样做是为了与在该路径添加新模块时发生的情况保持一致)。

我昨天刚刚经历了这个考验,这个答案非常有效。为了清晰起见,以下是我的步骤:

确保子模块被签入并推入到它的服务器。你还需要知道它在哪个分支上。 您需要子模块的URL !使用更多的.gitmodules,因为一旦你删除了子模块,它就不存在了 现在你可以使用deinit, rm和submodule add

例子

Git子模块在:Classes/lib/mustIReally 移动到:lib/AudioBus URL: http://developer.audiob.us/download/SDK.git

命令

    git submodule deinit Classes/lib/mustIReally
    git rm foo
    git submodule add http://developer.audiob.us/download/SDK.git lib/AudioBus

    # do your normal commit and push
    git commit -a 

注意:git mv不这样做。在所有。

我遇到同样的问题并成功地解决了它。感谢您在Github发布delete_git_submodule.md

要移除一个子模块,你需要:

从.gitmodules文件中删除相关的部分。 阶段。gitmodules的变化,git添加。gitmodules 从.git/config中删除相关的部分。(也许并不存在) 运行git rm——cached path_to_submodule(没有后面的斜杠)。 执行rm -rf .git/modules/path_to_submodule(没有后面的斜杠)。 Commit -m "已删除的子模块" 删除现在不跟踪的子模块文件rm -rf path_to_submodule

给出的解决方案对我不起作用,然而一个类似的版本却起作用了。

这是一个克隆的存储库,因此子模块git repos包含在顶级存储库.git目录中。所有阳离子都来自顶部存储库:

编辑.gitmodules并更改相关子模块的"path ="设置。(不需要更改标签,也不需要将该文件添加到索引。) 编辑.git/modules/name/config,修改子模块的"worktree ="设置 运行: Mv submodule newpath/submodule Git add -u Git增加了新路径/子模块

我想知道如果存储库是原子的,还是相对的子模块,在我的情况下,它是相对的(submodule/。Git是一个指向topproject/.git/modules/submodule的引用)

[更新:2014-11-26]正如Yar在下面总结的那样,在你做任何事情之前,确保你知道子模块的URL。如果未知,打开.git/。<name>.url。

对我有用的是使用git子模块deinit <submodule>和git rm <submodule-folder>删除旧的子模块。然后用新的文件夹名再次添加子模块并提交。在提交前检查git状态会显示旧子模块重命名为新名称,.gitmodule被修改。

$ 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"