0Pricing
Git Advanced: Monorepo, Submodules & Workflows · درس

إزالة الوحدات الفرعية وإلغاء تهيئتها

تعلّم الإجراء الصحيح والكامل لإزالة وحدة 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/submodule

Step 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/submodule

Step 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/submodule

Verify .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 .gitmodules

Step 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/submodule

What 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/modules cleanup — blocks re-adding the same path
  • Not committing the .gitmodules change — 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. مقدمة إلى الوحدات الفرعية في Git
  2. إضافة الوحدات الفرعية واستنساخها
  3. تحديث الوحدات الفرعية ومزامنتها
  4. إزالة الوحدات الفرعية وإلغاء تهيئتها
← العودة إلى Git Advanced: Monorepo, Submodules & Workflows