Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active January 21, 2022 08:06
Show Gist options
  • Save guitarrapc/43b2f5194f638e78505685e8c25347e9 to your computer and use it in GitHub Desktop.
Save guitarrapc/43b2f5194f638e78505685e8c25347e9 to your computer and use it in GitHub Desktop.
git submodule のチートシート。ベースはこれで。十分そろってる。 https://www.m3tech.blog/entry/git-submodule

サブモジュールごと clone したい

git clone https://example.com/repo-with-sub-modules --recursive

サブモジュールのファイルを取得したい

git submodule update --init --recursive

新しいバージョンを git checkout したら、他の人がサブモジュールを追加していた。

git submodule update --init --recursive

サブモジュールがどのバージョンを指しているか確認する

git submodule foreach git fetch # サブモジュールの最新情報を取得
git submodule status # ステータスを表示

サブモジュールのリビジョンを変える

cd sub-module # サブモジュールのディレクトリに移動
git fetch && git reset --hard origin/master # 適当なコマンドで、必要なバージョンをチェックアウトする

cd ../ # 親側に移動
git commit -a # 親側でコミット

サブモジュールを間違って変更してしまった

エディタのオート補完機能などで間違ってsubmoduleに影響が及んでしまうことが結構あると思います。

cd sub-module # サブモジュールのディレクトリに移動
git reset --hard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment