Удаление и деинициализация подмодулей
Изучите правильную полную процедуру удаления подмодуля Git из репозитория, включая деинициализацию, очистку .gitmodules и предотвращение сохранения остаточного состояния.
«Удаление и деинициализация подмодулей» — бесплатный урок Git Advanced: Monorepo, Submodules & Workflows на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 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.
Часто задаваемые вопросы
Урок «Удаление и деинициализация подмодулей» бесплатный?
Да — полный текст урока «Удаление и деинициализация подмодулей» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Git Advanced: Monorepo, Submodules & Workflows, подпишись на CoddyKit PRO. Курс Git Advanced: Monorepo, Submodules & Workflows содержит 4 уроков всего.
Чему я научусь в уроке «Удаление и деинициализация подмодулей»?
Изучите правильную полную процедуру удаления подмодуля Git из репозитория, включая деинициализацию, очистку .gitmodules и предотвращение сохранения остаточного состояния. Ты практикуешь Git Advanced: Monorepo, Submodules & Workflows с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 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
- Добавление и клонирование подмодулей
- Обновление и синхронизация подмодулей
- Удаление и деинициализация подмодулей