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

تثبيت الوحدات الفرعية على وسوم والتزامات محددة

أتقن التحكم الدقيق في الالتزام أو الوسم الذي تشير إليه الوحدة الفرعية، لضمان عمليات بناء قابلة لإعادة الإنتاج وتحديثات تبعية مدروسة وقابلة للمراجعة في سير العمل المتقدم.

تثبيت الوحدات الفرعية على وسوم والتزامات محددة درس مجاني في Git Advanced: Monorepo, Submodules & Workflows على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 = stable

Controlled 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 1

Why 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/engine

Quick 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.

الأسئلة الشائعة

هل درس «تثبيت الوحدات الفرعية على وسوم والتزامات محددة» مجاني؟

نعم — نص درس «تثبيت الوحدات الفرعية على وسوم والتزامات محددة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Git Advanced: Monorepo, Submodules & Workflows، انتقل إلى CoddyKit PRO. تتضمن دورة Git Advanced: Monorepo, Submodules & Workflows 4 دروس في المجموع.

ماذا ستتعلم في «تثبيت الوحدات الفرعية على وسوم والتزامات محددة»؟

أتقن التحكم الدقيق في الالتزام أو الوسم الذي تشير إليه الوحدة الفرعية، لضمان عمليات بناء قابلة لإعادة الإنتاج وتحديثات تبعية مدروسة وقابلة للمراجعة في سير العمل المتقدم. تتمرن على 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. العمل مع فروع الوحدات الفرعية
  2. الوحدات الفرعية المتداخلة والإعدادات المعقدة
  3. مشكلات الوحدات الفرعية الشائعة وإصلاحاتها
  4. تثبيت الوحدات الفرعية على وسوم والتزامات محددة
← العودة إلى Git Advanced: Monorepo, Submodules & Workflows