การตรึงซับโมดูลไว้กับแท็กและคอมมิตที่ระบุ
เชี่ยวชาญการควบคุมอย่างแม่นยำว่าซับโมดูลจะชี้ไปยังคอมมิตหรือแท็กใด เพื่อให้บิลด์ทำซ้ำได้ และการอัปเดตดีเพนเดนซีในเวิร์กโฟลว์ขั้นสูงเป็นไปอย่างตั้งใจและตรวจสอบได้
การตรึงซับโมดูลไว้กับแท็กและคอมมิตที่ระบุ เป็นบทเรียน Git Advanced: Monorepo, Submodules & Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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.
เรียนรู้ Git Advanced: Monorepo, Submodules & Workflows ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “การตรึงซับโมดูลไว้กับแท็กและคอมมิตที่ระบุ” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การตรึงซับโมดูลไว้กับแท็กและคอมมิตที่ระบุ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Git Advanced: Monorepo, Submodules & Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การตรึงซับโมดูลไว้กับแท็กและคอมมิตที่ระบุ”
เชี่ยวชาญการควบคุมอย่างแม่นยำว่าซับโมดูลจะชี้ไปยังคอมมิตหรือแท็กใด เพื่อให้บิลด์ทำซ้ำได้ และการอัปเดตดีเพนเดนซีในเวิร์กโฟลว์ขั้นสูงเป็นไปอย่างตั้งใจและตรวจสอบได้ คุณปฏิบัติ Git Advanced: Monorepo, Submodules & Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Git Advanced: Monorepo, Submodules & Workflows หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Git Advanced: Monorepo, Submodules & Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การตรึงซับโมดูลไว้กับแท็กและคอมมิตที่ระบุ” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Git Advanced: Monorepo, Submodules & Workflows นี้ได้ไหม
ได้ บทเรียน Git Advanced: Monorepo, Submodules & Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การทำงานกับสาขาของ Submodule
- Submodule ซ้อนกันและการตั้งค่าซับซ้อน
- ปัญหาและวิธีแก้ไข Submodule ที่พบบ่อย
- การตรึงซับโมดูลไว้กับแท็กและคอมมิตที่ระบุ