การลบและยกเลิกการเริ่มต้นซับโมดูล
เรียนรู้ขั้นตอนที่ถูกต้องและครบถ้วนในการลบซับโมดูล Git ออกจากรีโพซิทอรี รวมถึงการยกเลิกการเริ่มต้น การล้าง .gitmodules และการป้องกันสถานะตกค้าง
การลบและยกเลิกการเริ่มต้นซับโมดูล เป็นบทเรียน Git Advanced: Monorepo, Submodules & Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Git Advanced: Monorepo, Submodules & Workflows และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
When You Need to Remove a Submodule
Submodules are added to pull in external code, but requirements change. You may need to remove one when the dependency is replaced, vendored directly, or simply no longer needed.
Removal is more involved than deleting a folder: a submodule lives in several places at once, and missing one leaves your repo in a broken state.
Where a Submodule Lives
A submodule has three footprints:
.gitmodules— the declarative config.git/config— your local active config.git/modules/<path>— the cached submodule git data
Plus the working tree folder itself. Clean removal touches all of these.
Step 1: Deinitialize
Start with git submodule deinit. This unregisters the submodule and removes its entry from .git/config, leaving the rest intact for now.
git submodule deinit -f path/to/submoduleStep 2: Remove from the Index
Use git rm to remove the submodule from tracking and from the working tree. This also updates .gitmodules automatically in modern Git.
git rm -f path/to/submoduleStep 3: Clean the Cached Git Data
The submodule's git data lingers under .git/modules. Remove it so a future submodule with the same path does not collide.
rm -rf .git/modules/path/to/submoduleVerify .gitmodules Is Clean
Open .gitmodules and confirm the [submodule "..."] block is gone. If git rm left an empty file or a stale entry, fix it by hand and stage the change.
git diff --cached .gitmodulesStep 4: Commit the Removal
The removal must be committed so collaborators get the change. The commit captures the deleted folder, the updated .gitmodules, and the dropped index entry.
git commit -m 'Remove path/to/submodule'The Manual Fallback
On older Git versions git rm may not edit .gitmodules for you. The manual path:
git config -f .gitmodules --remove-section submodule.path/to/submodule
git add .gitmodules
git rm --cached path/to/submodule
rm -rf path/to/submoduleWhat Collaborators See
When teammates pull the removal commit, the folder disappears from tracking. But their local .git/modules cache and .git/config entry may persist. Tell them to run git submodule sync and clean up if needed.
Common Mistakes
- Deleting only the folder with
rm -rf— leaves a broken index entry - Forgetting
.git/modulescleanup — blocks re-adding the same path - Not committing the
.gitmoduleschange — others still see the submodule
A Reusable Checklist
Whenever you remove a submodule, run through: deinit, rm, clean modules cache, verify .gitmodules, commit. Following the same order every time prevents the half-removed states that confuse a whole team.
Quick Check
Test your understanding of removing submodules.
Recap
You learned the complete removal procedure: deinit to unregister, git rm to drop tracking, clean .git/modules to clear the cache, verify .gitmodules, then commit. Following this checklist every time keeps both your repo and your collaborators' clones healthy.
คำถามที่พบบ่อย
บทเรียน “การลบและยกเลิกการเริ่มต้นซับโมดูล” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การลบและยกเลิกการเริ่มต้นซับโมดูล” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Git Advanced: Monorepo, Submodules & Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การลบและยกเลิกการเริ่มต้นซับโมดูล”
เรียนรู้ขั้นตอนที่ถูกต้องและครบถ้วนในการลบซับโมดูล Git ออกจากรีโพซิทอรี รวมถึงการยกเลิกการเริ่มต้น การล้าง .gitmodules และการป้องกันสถานะตกค้าง คุณปฏิบัติ 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 ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- บทนำสู่ Git Submodule
- การเพิ่มและโคลน Submodule
- การอัปเดตและซิงโครไนซ์ Submodule
- การลบและยกเลิกการเริ่มต้นซับโมดูล