Lesson 7 / الدرس 7
git commit, and a message worth reading / git commit ورسالة تستحق القراءة
The command is short. The message is the part that matters, because it is the only thing explaining why — and in six months you will be the stranger reading it.
الأمر قصير. والرسالة هي الجزء المهم، لأنها الشيء الوحيد الذي يشرح لماذا — وبعد ستة أشهر ستكون أنت الغريب الذي يقرؤها.
git commit -m "Fix the contact form losing the subject line"
[main 3f9a21c] Fix the contact form losing the subject line
1 file changed, 4 insertions(+), 2 deletions(-)
3f9a21c is the start of the commit's identifier — its name, which you can use to refer to it forever. 3f9a21c بداية معرّف الـcommit — اسمها، الذي تستطيع الإشارة إليها به إلى الأبد.The message is the whole point
Git already records what changed — you can always read the diff. What no tool can recover is why. That reasoning exists only in your head at the moment you commit, and the message is the one chance to write it down. Six months later, "fix" tells you nothing and "Fix the contact form losing the subject line when the message was long" tells you everything.
Add search to the products page
The catalogue passed 400 items and customers were scrolling
to find things they already knew the name of.
Searches the name and the description. Deliberately not the
supplier code, which is internal and would leak it into a
public page.
| Command | Does |
|---|---|
| git commit -m "…" | Commit what is staged, with this message |
| git commit | Open your editor to write a longer message |
| git commit -a -m "…" | Stage every TRACKED change, then commit |
| git commit --amend | Replace the last commit — see the warning |
-a skips git add for files git already tracks. It does not include new files, which is a common surprise: an untracked file stays untracked no matter how many times you use it.
-a يتخطى git add للملفات التي يتتبعها git أصلًا. ولا يشمل الملفات الجديدة، وهي مفاجأة شائعة: فالملف غير المتتبَّع يبقى كذلك مهما استخدمته مرات.Fixing the last commit
You commit, and immediately notice a typo in the message, or a file you meant to include. git commit --amend replaces the last commit with a new one — stage the missing file first if there is one, and you get one clean commit instead of a second one saying "oops".
git commit --amend يستبدل بآخر commit واحدة جديدة — جهّز الملف الناقص أولًا إن وُجد، فتحصل على commit نظيفة واحدة بدل ثانية تقول "عذرًا".-m، وعلامة الصح هي git commit. وسطر فارغ ثم نص إضافي في المربع نفسه يعطيك الصيغة الطويلة. وقائمة … فيها "Commit Staged (Amend)" للحالة أعلاه — والقاعدة نفسها في عدم تعديل ما دفعته.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1. Why does the message matter when git already records the changes?
The reasoning exists only in your head at that moment. Nothing else in the repository can reconstruct it later.
2.
What does git commit -a not include?
git commit -a؟It stages changes to files git already knows. An untracked file needs an explicit git add, once.
git add صريحًا مرة.
3.
When is --amend safe?
--amend آمنًا؟It replaces the commit and changes its identifier. Once others have the old one, your histories disagree.
Score / النتيجة: 0 / 3
Your task / مهمتك
Make the three commits you planned last lesson, for real. Show each git commit and its output. Then write a short critique of your own messages: for each one, say whether it passes the four rules, and rewrite any that does not. Finish by using --amend once to improve a message, and explain why doing so was safe.
اصنع الـcommits الثلاث التي خططتها الدرس الماضي فعلًا. وأظهر كل git commit ومخرَجه. ثم اكتب نقدًا قصيرًا لرسائلك أنت: قل لكل واحدة هل تجتاز القواعد الأربع، وأعد كتابة ما لا يجتازها. واختم باستخدام --amend مرة لتحسين رسالة، واشرح لماذا كان ذلك آمنًا.
- Three real commits, with their output ثلاث commits حقيقية بمخرَجها
- Each message checked against the four rules كل رسالة مفحوصة بالقواعد الأربع
- One amend, with before and after تعديل واحد، بقبل وبعد
- Why the amend was safe in your case لماذا كان التعديل آمنًا في حالتك