本文介绍了如何在Git存储库中移动现有的Git子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



假设我在中有下列条目: .gitmodules file:

  [submodule.emacs.d / vimpulse] 


$ =

必须输入什么信息才能将 .emacs.d / vimpulse 目录移至 .emacs.d / vendor / vimpulse 不先删除它(解释
和),然后重新添加。



Git是否真的需要子模块标记中的整个路径

  [submodule .emacs.d / vimpulse] 

还可以只存储子项目的名称?

  
$ b $ div class =h2_lin>解决方案

注意:正如评论中提到的,这个答案指的是旧版本git所需的步骤。 Git现在支持移动子模块:






与删除子模块的方式类似(请参阅):


  1. 编辑 .gitmodules 并更改如果需要的话,创建子目录的父目录,并将其放在索引中,并将其放在 git add .gitmodules

  2. 子模块的新位置( mkdir -p new / parent )。

  3. 将所有内容从旧目录移动到新目录( mv -vi old / parent / submodule new / parent / submodule )。

  4. 确保Git跟踪这个目录( git add new / parent )。

  5. 使用 git rm --cached old / parent / submodule

  6. 移动目录 .git / modules / old / parent / submodule 其所有内容 .git / modules / new / parent / submodule

  7. 编辑 .git / modules / new / parent / config 文件,确保worktree项指向新的位置,所以在这个例子中它应该是 worktree = ../。 ./../../../新/父/模块。通常应该有两个 .. 然后在那个地方的直接路径中的目录。 编辑文件 new / parent / module / .git ,确保其中的路径指向主项目中的正确新位置 .git 文件夹,所以在本例中 gitdir:../../../。git / modules / new / parent / submodule



    git status 输出结果如下:

     #在分支主机上
    #要提交的更改:
    #(使用git reset HEAD< file> ...以取消存储)

    #modified:.gitmodules
    #重命名为:old / parent / submodule - >新/父/子模块


  8. 最后,提交更改。 p>



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:


It’s similar to how you remove a submodule (see How do I remove a submodule?):

  1. Edit .gitmodules and change the path of the submodule appropriately, and put it in the index with git add .gitmodules.
  2. If needed, create the parent directory of the new location of the submodule (mkdir -p new/parent).
  3. Move all content from the old to the new directory (mv -vi old/parent/submodule new/parent/submodule).
  4. Make sure Git tracks this directory (git add new/parent).
  5. Remove the old directory with git rm --cached old/parent/submodule.
  6. Move the directory .git/modules/old/parent/submodule with all its content to .git/modules/new/parent/submodule.
  7. 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 .. then directories in the direct path in that place.
  8. 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
    #
    

  9. Finally, commit the changes.

这篇关于如何在Git存储库中移动现有的Git子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:30