Lesson 4 / الدرس 4
The three places a file can be / المواضع الثلاثة التي قد يكون فيها الملف
Almost every confusing thing about git comes from not knowing this. A file is in your folder, or staged, or committed — and each command moves it between exactly two of those.
كل ما يحيّر في git تقريبًا يأتي من عدم معرفة هذا. فالملف إما في مجلدك، أو مجهَّز، أو مودَع — وكل أمر ينقله بين اثنين منها بالضبط.
This lesson has no new commands in it. It is a picture, and it is the single most useful thing to hold in your head while learning git — because every command in the next six lessons is an arrow between two of these three places.
working directory staging area repository
(your actual files) (what is next) (the history)
│ ────── git add ──────> │ │
│ │ ── git commit ──> │
│ <──────────── git restore / git checkout ─── │
Why the middle one exists
The staging area is the part people ask about. Why not just commit the files? Because your working directory rarely contains exactly one coherent change. You fixed a bug, and while you were there you renamed a variable and added a note to a different file. Staging lets you commit the bug fix on its own, with a message about the bug, and commit the rest separately.
| Git calls a file | When | git status colour |
|---|---|---|
| untracked | It is new and git has never seen it | Red, under "untracked files" |
| modified | It is tracked and you changed it | Red, under "not staged" |
| staged | You ran git add on it | Green, under "to be committed" |
| committed | It is in the history and unchanged since | Not listed at all |
The last row is why a clean git status is short. Anything git does not mention is already safely in the history, exactly as it is on disk.
git status النظيف. فكل ما لا يذكره git موجود بأمان في التاريخ، كما هو على القرص تمامًا.The same file in two places at once
One consequence surprises everybody. Stage a file, then edit it again before committing, and git lists it twice — once as staged and once as modified. That is not a bug: the staged version is the one you chose, and the file on disk has since moved on. Committing now saves the staged version, not what is on disk.
git commit لا يستطيع git أن يعيد إليك شيئًا. ولهذا كانت "أودع كثيرًا" هي النصيحة التي يعطيها الجميع.+ بجانب ملف هي git add. وإن حيّرك تخطيط القائمتين يومًا، فهو هذا الدرس على الشاشة.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1. What is the staging area for?
It lets one messy working directory become several clean commits, each with a message that is actually true of its contents.
2. You stage a file, then edit it again, then commit. What is saved?
The commit saves what was staged. That is why git lists the file twice — the two versions genuinely differ.
3. Which of the three places is permanent?
Only a commit can be returned to. Staged work is a list of intentions and uncommitted work is just a file on a disk.
Score / النتيجة: 0 / 3
Your task / مهمتك
Draw the three places as a page, in your own words: what each one is, what it is for, and which command moves a file into it. Then explain the staging area to someone who thinks it is pointless — give a concrete example of a working directory containing two unrelated changes and say what you would commit first and why.
ارسم المواضع الثلاثة في صفحة بكلماتك: ما كل واحد، وما وظيفته، وأي أمر ينقل ملفًا إليه. ثم اشرح منطقة التجهيز لمن يظنها بلا فائدة — بمثال محدد لمجلد عامل فيه تغييران غير مترابطين وقل ما الذي ستودعه أولًا ولماذا.
- All three places, in your own words المواضع الثلاثة كلها بكلماتك
- The command that moves a file into each الأمر الذي ينقل ملفًا إلى كل واحد
- A concrete two-change example مثال محدد بتغييرين
- Which is permanent, said explicitly أيها دائم، مقولًا صراحةً