【Git】サブモジュールのディレクトリ名を変更する
Gitにおけるサブモジュールのディレクトリ名と関連する設定ファイルを更新する手順
サブモジュールのディレクトリ名を変更
1. ディレクトリ名を変更
cd /path/to/repository-root git mv olddir newdir
これによりサブモジュールのディレクトリと.gitmodules
ファイルが自動で更新される。.git/config
ファイルは後で手動で更新。
変更をコミット
git add . git commit -m "olddir -> newdir"
2. .gitmodulesのパスを手動で更新
vim .gitmodules
次のように変更
[submodule “www/old/scripts”] path = www/new/scripts -> [submodule “www/new/scripts”] path = www/new/scripts
3. .git/configファイルのパスを手動で更新
vim .git/config
次のように変更
[submodule “www/old/scripts”] -> [submodule “www/new/scripts”]
4. サブモジュールのURLを同期
git submodule sync
これでサブモジュールのディレクトリ名と関連する設定ファイルの更新が完了しました。
5. サブモジュールを最新のコミットに更新する(オプション)
git submodule update --init --recursive
サブモジュールの削除
.gitmodules
と.git/config
からサブモジュールのエントリを削除し、以下のコマンドを実行。
vim .gitmodules # remove submodule vim .git/config # remove submodule git rm — cached path/to/submodule rm -rf path/to/submodule git commit -m “remove submodule”