LoginSignup
19
19

More than 5 years have passed since last update.

gitのsubmoduleを簡単に削除するコマンド

Posted at

以下の投稿を見てコマンドだけでsubmoduleを削除できることを知ったので、スクリプト化しました。

git-submodule-remove.sh
#!/bin/bash

if [ -z "$1" ]; then
    echo "Error: Specify a path to the submodule directory" 1>&2
    exit 1
fi

if [ ! "$(pwd)" = "$(git rev-parse --show-toplevel)" ]; then
    echo 'Error: Run again after: cd "$(git rev-parse --show-toplevel)"' 1>&2
    exit 1
fi

git config --remove-section submodule."$1" || exit 1
git config --file .gitmodules --remove-section submodule."$1" || exit 1
git rm --cached "$1" || exit 1
rm -rf "$1" || exit 1

これで1コマンドでsubmoduleが削除できるようになります。

$ git-submodule-remove path/to/sumodule-directory

このコマンドはgitディレクトリのトップレベルで実行します。
また、指定するsubmoduleはトップレベルからの相対パスです。

19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19