サブモジュールを特定のタグやコミットに固定
サブモジュールが指すコミットやタグを正確に制御し、高度なワークフローで再現可能なビルドと意図的でレビュー可能な依存関係更新を実現する方法を習得します。
「サブモジュールを特定のタグやコミットに固定」はCoddyKit上の無料Git Advanced: Monorepo, Submodules & Workflowsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはGit Advanced: Monorepo, Submodules & Workflows学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Git Advanced: Monorepo, Submodules & Workflowsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Submodules Pin Commits, Not Branches
A common misconception: a submodule tracks a branch. In reality, the superproject records a specific commit SHA for each submodule. Branches only matter when you choose to update.
This pinning is what makes submodule-based builds reproducible across machines and time.
Inspecting the Pinned Commit
See exactly which commit each submodule is locked to with git submodule status. The leading SHA is the recorded pin.
git submodule status
# +a1b2c3d libs/engine (v2.3.0-4-ga1b2c3d)Reading the Status Prefix
- (space) — submodule is at the pinned commit
- + — checked-out commit differs from the pin
- - — submodule is not initialized
- U — merge conflicts in the submodule
Pinning to a Specific Tag
To pin to a released tag, enter the submodule, check out the tag, then commit the new pointer in the superproject.
cd libs/engine
git fetch --tags
git checkout v2.4.0
cd ../..
git add libs/engine
git commit -m 'Pin engine to v2.4.0'Pinning to an Exact SHA
Sometimes you need a commit between releases. Check out the exact SHA inside the submodule, then record it in the superproject.
cd libs/engine
git checkout 9f8e7d6
cd ../..
git add libs/engine
git commit -m 'Pin engine to 9f8e7d6 hotfix'Detached HEAD Is Normal Here
Checking out a tag or SHA puts the submodule in detached HEAD. That is expected and correct for pinning. You only attach to a branch when you intend to develop inside the submodule.
Optional Branch Tracking
You can record a preferred branch in .gitmodules so git submodule update --remote knows what to follow. The pin still wins until you explicitly update.
[submodule "libs/engine"]
path = libs/engine
url = https://example.com/engine.git
branch = stableControlled Updates with --remote
To advance a submodule to the latest of its tracked branch, use --remote. Review the diff before committing the new pin so the bump is deliberate.
git submodule update --remote libs/engine
git diff --submodule
git add libs/engine && git commit -m 'Bump engine'Enforcing Pins in CI
Builds should fail if a submodule drifts from its pin. A CI guard checks that the checked-out SHA matches the recorded one.
git submodule status | grep '^+' && echo 'Submodule drift!' && exit 1Why Deliberate Pinning Matters
Accidental submodule bumps are a frequent source of mysterious build breaks. Treating each pin change as a reviewable, intentional commit keeps your dependency surface predictable and auditable.
Reverting a Bad Pin
If a pin update breaks the build, revert it like any other change: the superproject commit that moved the pointer can be undone, snapping the submodule back to its previous SHA.
git revert <pin-bump-commit>
git submodule update --init libs/engineQuick Check
Test your understanding of submodule pinning.
Recap
You learned that submodules pin commit SHAs, how to read git submodule status prefixes, how to pin to a tag or exact SHA, why detached HEAD is normal, optional branch tracking, controlled --remote updates, and CI drift enforcement. Deliberate pinning keeps advanced submodule setups reproducible.
よくある質問
「サブモジュールを特定のタグやコミットに固定」レッスンは無料ですか?
はい。「サブモジュールを特定のタグやコミットに固定」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Git Advanced: Monorepo, Submodules & Workflowsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Git Advanced: Monorepo, Submodules & Workflowsコースには全4レッスンが含まれています。
「サブモジュールを特定のタグやコミットに固定」で何を学びますか?
サブモジュールが指すコミットやタグを正確に制御し、高度なワークフローで再現可能なビルドと意図的でレビュー可能な依存関係更新を実現する方法を習得します。 ブラウザで直接実行するハンズオンコードでGit Advanced: Monorepo, Submodules & Workflowsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Git Advanced: Monorepo, Submodules & Workflowsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのGit Advanced: Monorepo, Submodules & Workflowsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「サブモジュールを特定のタグやコミットに固定」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このGit Advanced: Monorepo, Submodules & Workflowsレッスンでコードを書いて実行できますか?
はい。すべてのGit Advanced: Monorepo, Submodules & Workflowsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Submoduleのブランチ操作
- ネストされたSubmodulesと複雑な構成
- Submodulesでよくある問題と解決策
- サブモジュールを特定のタグやコミットに固定