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

تخزين التغييرات وانتقاؤها

أتقن `git stash` لحفظ التغييرات مؤقتًا و`git cherry-pick` لتطبيق التزامات محددة عبر الفروع.

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

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Why Use Git Stash?

Mid-feature and an urgent bug fix lands? git stash temporarily shelves your uncommitted changes so you can switch branches without committing half-done work.

Saving Your Changes Temporarily

Run git stash to save your modified and staged changes, then Git resets your working directory to a clean HEAD. Your work is safely tucked away.

git status
# On branch feature-x
# Changes to be committed:
#   new file:   new_feature.txt
# Changes not staged for commit:
#   modified:   index.html

git stash
# Saved working directory and index state WIP on feature-x: ...
# HEAD is now at ...

git status
# On branch feature-x
# nothing to commit, working tree clean

Viewing Your Stash Stack

You can hold multiple stashes. git stash list shows them all, each indexed — stash@{0} being the most recent.

git stash list
# stash@{0}: WIP on feature-x: ...
# stash@{1}: WIP on bugfix-branch: ...

Bringing Stash Back: Apply

git stash apply restores your most recent stash into the working directory. Want an older one? Name it, like git stash apply stash@{1}.

git checkout bugfix-branch
git stash apply stash@{1}
# On branch bugfix-branch
# Changes not staged for commit:
#   modified:   bug.js

Apply vs. Pop: What's the Difference?

apply vs pop: apply restores changes but keeps the stash in the list; pop restores them and removes the stash. Use pop when you're done with it.

git stash list
# stash@{0}: WIP on feature-x: ...

git stash pop
# On branch feature-x
# Changes not staged for commit:
#   modified:   index.html
# Dropped stash stash@{0} (...

git stash list
# (empty output, stash is gone)

Cleaning Up Stashes

Clean up stashes you no longer need: git stash drop <id> removes one, git stash clear removes all. Clear can't be undone, so be careful.

git stash list
# stash@{0}: WIP on feature-x: ...
# stash@{1}: WIP on old-bug: ...

git stash drop stash@{1}
# Dropped stash stash@{1} (...

git stash list
# stash@{0}: WIP on feature-x: ...

Introducing Git Cherry-Pick

Need just one commit from another branch, not its whole history? git cherry-pick applies a single commit's changes onto your current branch.

Applying a Single Commit

Find the commit hash with git log --oneline, switch to your target branch, then git cherry-pick <hash> to bring just that change over.

git log --oneline
# a1b2c3d Fix: Critical typo in header
# e4f5g6h Feat: Add user profiles

git checkout main
# Switched to branch 'main'

git cherry-pick a1b2c3d
# [main] Fix: Critical typo in header
#  1 file changed, 1 insertion(+), 1 deletion(-)

Resolving Cherry-Pick Conflicts

Cherry-picking can conflict like a merge. Resolve manually, git add the files, then git cherry-pick --continue — or --abort to cancel.

git cherry-pick a1b2c3d
# Auto-merging header.js
# CONFLICT (content): Merge conflict in header.js
# error: could not apply a1b2c3d...

# (Resolve conflicts, then:)
git add header.js
git cherry-pick --continue

Stash & Cherry-Pick Quiz

You are on the feature-A branch, with uncommitted changes. An urgent fix needs to go into main. You stash your changes, switch to main, and fix the bug with a commit (hash: 789abc). Now you want to apply this fix to feature-A and return to your work.

Lesson Summary

Recap: git stash shelves uncommitted work so you can switch branches cleanly, and git cherry-pick grabs a single commit from one branch onto another.

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

هل درس «تخزين التغييرات وانتقاؤها» مجاني؟

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

ماذا ستتعلم في «تخزين التغييرات وانتقاؤها»؟

أتقن `git stash` لحفظ التغييرات مؤقتًا و`git cherry-pick` لتطبيق التزامات محددة عبر الفروع. تتمرن على Git Advanced: Monorepo, Submodules & Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Git Advanced: Monorepo, Submodules & Workflows؟

لا تُشترط خبرة سابقة. Git Advanced: Monorepo, Submodules & Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «تخزين التغييرات وانتقاؤها»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Git Advanced: Monorepo, Submodules & Workflows هذا؟

نعم. كل درس في Git Advanced: Monorepo, Submodules & Workflows يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

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