Usuwanie i wyrejestrowywanie submodułów
Poznaj prawidłową, kompletną procedurę usuwania submodułu Git z repozytorium, obejmującą wyrejestrowanie, czyszczenie pliku .gitmodules i unikanie pozostałości po wcześniejszym stanie.
Usuwanie i wyrejestrowywanie submodułów to bezpłatna lekcja Git Advanced: Monorepo, Submodules & Workflows na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Git Advanced: Monorepo, Submodules & Workflows, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Git Advanced: Monorepo, Submodules & Workflows zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Często zadawane pytania
Czy lekcja „Usuwanie i wyrejestrowywanie submodułów” jest bezpłatna?
Tak — pełny tekst „Usuwanie i wyrejestrowywanie submodułów” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Git Advanced: Monorepo, Submodules & Workflows, przejdź na CoddyKit PRO. Kurs Git Advanced: Monorepo, Submodules & Workflows zawiera 4 lekcji w sumie.
Co nauczysz się w „Usuwanie i wyrejestrowywanie submodułów”?
Poznaj prawidłową, kompletną procedurę usuwania submodułu Git z repozytorium, obejmującą wyrejestrowanie, czyszczenie pliku .gitmodules i unikanie pozostałości po wcześniejszym stanie. Ćwiczysz Git Advanced: Monorepo, Submodules & Workflows z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Git Advanced: Monorepo, Submodules & Workflows?
Nie wymagamy żadnego doświadczenia. Git Advanced: Monorepo, Submodules & Workflows w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Usuwanie i wyrejestrowywanie submodułów”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Git Advanced: Monorepo, Submodules & Workflows?
Tak. Każda lekcja Git Advanced: Monorepo, Submodules & Workflows zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Wprowadzenie do Git Submodules
- Dodawanie i klonowanie submodułów
- Aktualizowanie i synchronizowanie submodułów
- Usuwanie i wyrejestrowywanie submodułów