最終更新日: 2021年2月7日
gitでsubmoduleを削除する方法をご紹介!
一度gitで登録したサブモジュール(submodule)を削除する方法を紹介します。git submodule addした後すぐの場合や既にgitで登録済のサブモジュールを削除する方法を解説します。
gitでsubmoduleを削除したい
gitでsubmoduleを導入したはいいが、後になって必要なくなったので削除したいというケースを考えます。
gitのsubmoduleは簡単に登録できる反面、削除は少しやっかいです。それぞれのケースでgitのsubmoduleの削除方法を紹介していきます。
gitでsubmoduleを削除する方法
ケースごとに紹介していきます。
すでにリポジトリに登録済みのsubmodule
すでにgitでリポジトリに登録済のsubmoduleは以下の手順で削除しましょう。
submoduleの削除
git submodule deinit -f サブモジュールのパス
git rm -f サブモジュールのパス
rm -rf .git/modules/サブモジュールのパス
まだリポジトリに登録していない
まだsubmoduleをリポジトリに登録していない場合(git submodule add
しただけ)は下記の手順で実行しましょう。
submoduleの削除
git reset
rm -rf .git/modules/サブモジュールのパス
# .gitmodulesを戻す
git config --local --remove-section submodule.サブモジュールのパス
git config -f .gitmodules --remove-section submodule.サブモジュールのパス
# もしはじめてのサブモジュールであれば.gitmodulesも削除
rm .gitmodules