移動子模組
Version > 1.8
跑:
$ git mv old/path/to/module new/path/to/module
Version <= 1.8
-
編輯
.gitmodules並適當更改子模組的路徑,並使用git add .gitmodules將其放入索引中。 -
如果需要,建立子模組( ) 的新位置的父目錄。
mkdir -p new/path/to -
將所有內容從舊目錄移動到新目錄( )。
mv -vi old/path/to/module new/path/to/submodule -
確保 Git 跟蹤此目錄( )。
git add new/path /to -
刪除舊目錄。
git rm --cached old/path/to/module -
將包含其所有內容的目錄移動到。
.git/modules/ old/path/to/module.git/modules/ new/path/to/module -
編輯檔案,確保 worktree 項指向新位置,因此在此示例中應該是。通常,在該位置的直接路徑中應該還有兩個
..然後目錄。。編輯檔案,確保其中的路徑指向主專案.git資料夾中的正確新位置,因此在此示例中。.git/modules/ new/path/to /configworktree = ../../../../../ old/path/to/modulenew/path/to/module /.gitgitdir: ../../../.git/modules/ new/path/to/module之後
git status輸出如下:# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: .gitmodules # renamed: old/path/to/submodule -> new/path/to/submodule # -
最後,提交更改。