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

إعادة الأساس التفاعلية وتعديل الالتزامات

تعلّم إعادة كتابة السجل باستخدام `git rebase -i` للحصول على التزامات أنظف، واستخدم `git commit --amend` لتعديل آخر التزاماتك.

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

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

Clean Up Your Git History

Git history gets messy — a forgotten file, a typo'd message, ten tiny commits that should be one. Git lets you rewrite history to clean it up.

Amending Your Last Commit

git commit --amend fixes your most recent commit: change the message, add forgotten files, or tweak content. It replaces the last commit with a tidier one.

Amending a Commit Example

Forgot a file right after committing? Stage it, then git commit --amend folds it into the last commit. Here's the flow.

# 1. Make some changes and commit
echo "Initial content" > file1.txt
git add file1.txt
git commit -m "Add file1"

# 2. Realize you forgot file2.txt
echo "More content" > file2.txt
git add file2.txt

# 3. Amend the last commit to include file2.txt
git commit --amend --no-edit

Introducing Interactive Rebase

Need to fix commits further back, not just the last one? Interactive rebase (git rebase -i) is a full editor for a series of commits.

Getting Started with Rebase -i

Start an interactive rebase by naming a commit before your target range. To edit the last three commits, use HEAD~3.

git rebase -i HEAD~3

Rebase Commands: Pick, Reword, Squash

The rebase editor lists commits with commands you can swap: pick keeps it, reword edits the message, squash/fixup merge it up, edit pauses to amend.

Rewording a Commit Message

To change an older commit's message, switch its line from pick to reword in the editor. Git then prompts you for the new message.

# Original rebase editor content:
# pick 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docs

# Change 'pick' to 'reword' for the first commit:
# reword 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docs

Squashing Commits Together

Got several small commits that belong together? squash merges them into one meaningful commit — change the lines below pick to squash.

# Original commits:
# pick abc1234 Add user registration form
# pick def5678 Add validation for email field
# pick ghi9012 Fix styling on form

# To squash the last two into the first:
# pick abc1234 Add user registration form
# squash def5678 Add validation for email field
# squash ghi9012 Fix styling on form

Editing an Older Commit

The edit command pauses the rebase at a specific commit. Make changes, git add, git commit --amend, then git rebase --continue.

When to Be Careful with Rewriting

Rewriting changes commit IDs — safe for local-only commits. Never rewrite history that's already pushed and shared; it wrecks your collaborators' work.

Quick Check: History Rewriting

You've made a commit with the message "Fix bug". You then realize you forgot to include one small file in that commit. What is the most appropriate Git command to fix this, assuming you haven't pushed the commit yet?

Recap: Cleaner Commits

Recap: git commit --amend fixes the last commit, while git rebase -i rewrites a series — reword, squash, fixup, or edit. Just be careful on shared branches.

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

هل درس «إعادة الأساس التفاعلية وتعديل الالتزامات» مجاني؟

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

ماذا ستتعلم في «إعادة الأساس التفاعلية وتعديل الالتزامات»؟

تعلّم إعادة كتابة السجل باستخدام `git rebase -i` للحصول على التزامات أنظف، واستخدم `git commit --amend` لتعديل آخر التزاماتك. تتمرن على Git Advanced: Monorepo, Submodules & Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

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

لا تُشترط خبرة سابقة. Git Advanced: Monorepo, Submodules & Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 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