Lesson 8 / الدرس 8
git log: reading your own history / git log: قراءة تاريخك
The history is only useful if you can search it. One command shows it, and a handful of options turn it into an answer to "when did this break, and who changed it?"
التاريخ لا ينفع إلا إن استطعت البحث فيه. وأمر واحد يعرضه، وحفنة خيارات تحوّله إلى جواب لسؤال "متى انكسر هذا، ومن غيّره؟"
$ git log
commit 3f9a21c8b4e7d2a1f6c9e0b5d8a3f7c2e1b4d6a9
Author: Ahmed Hamdi <ahmed@example.com>
Date: Sun Aug 3 14:02:11 2026 +0300
Fix the contact form losing long subject lines
less, from lesson 5 of the terminal course. less من الدرس 5 في دورة الطرفية.The forms worth knowing
| Command | Shows |
|---|---|
| git log --oneline | One line per commit — the one you will use most |
| git log --oneline --graph | The same, with branches drawn beside it |
| git log -5 | Only the last five |
| git log --stat | Which files each commit touched, and by how much |
| git log -p | The full diff of every commit |
| git log -- index.html | Only commits that touched this file |
| git log --author="Ahmed" | Only commits by this person |
| git log --since="2 weeks ago" | Only recent ones |
The two dashes before a filename are not a typo: they tell git that what follows is a path and not a branch name, which matters when something is both.
$ git log --oneline
3f9a21c Fix the contact form losing long subject lines
8c4e102 New colour palette
b71d9f3 Fix typo in the footer
a02c5e8 Add the about page
9d3f1b7 Initial commit
Looking at one commit
git show 3f9a21c prints one commit in full: its message, its author, and every line it changed. You will use it constantly once git log has narrowed things down to a suspect. Seven characters of the identifier are enough — git works out the rest as long as it is unambiguous.
git show 3f9a21c يطبع commit واحدة كاملة: رسالتها ومؤلفها وكل سطر غيّرته. وستستخدمه باستمرار ما إن يضيّق git log الأمر إلى مشتبه به. وسبعة محارف من المعرّف تكفي — فـgit يستنتج الباقي ما دام غير ملتبس.git blame سيخبرك بأمانة أن السطر 40 تغيّر في commit اسمها "update"، فتبقى حيث بدأت بالضبط. وعمل كتابة رسالة حقيقية يُبذل وقت الإيداع، ويُقبض هنا.
Two ways to name a commit without its identifier, which appear everywhere: HEAD means the commit you are currently on, and HEAD~1 the one before it, HEAD~3 three back. git show HEAD is the quickest way to see what you just committed, and it is worth running immediately after every commit while you are learning.
HEAD تعني الـcommit التي أنت عليها الآن، وHEAD~1 التي قبلها، وHEAD~3 ثلاثًا للوراء. وgit show HEAD أسرع طريقة لرؤية ما أودعته للتو، ويستحق التنفيذ فور كل commit وأنت تتعلم.git log للملف المفتوح، ونقر مُدخَل يعرض فرق تلك الـcommit. وأما git blame فالمحرر يعرض آخر تغيير للسطر الحالي في آخره؛ وإضافة GitLens تحوّل ذلك إلى عرض blame كامل.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1. Which command tells you who last changed a particular line?
git blame annotates every line with its last commit. Take that identifier to git show for the message explaining it.
git blame على كل سطر بآخر commit له. وخذ ذلك المعرّف إلى git show للرسالة التي تشرحه.
2.
What does HEAD~1 mean?
HEAD~1؟HEAD is where you are; the tilde counts backwards from it. It saves looking up an identifier for anything recent.
HEAD هي حيث أنت؛ والعلامة تعدّ رجوعًا منها. وتوفّر البحث عن معرّف لأي شيء حديث.3. Why do vague commit messages hurt most at this lesson?
The tools work perfectly and hand you a commit called "update". The work is done at commit time and repaid here.
Score / النتيجة: 0 / 3
Your task / مهمتك
Explore the history of a real repository — yours if it has several commits, otherwise clone any public project. Answer three questions with commands and show both: how many commits it has and by whom, which commits touched one particular file, and who last changed a specific line and why. For the last one, follow git blame through to git show and quote the message.
استكشف تاريخ مستودع حقيقي — مستودعك إن كان فيه عدة commits، وإلا فانسخ أي مشروع عام. وأجب ثلاثة أسئلة بأوامر وأظهر الاثنين: كم فيه من commits وممن، وأي commits مسّت ملفًا بعينه، ومن غيّر سطرًا محددًا آخر مرة ولماذا. وفي الأخير، تابع git blame حتى git show واقتبس الرسالة.
- Three real questions answered with real output ثلاثة أسئلة حقيقية مُجابة بمخرَج حقيقي
- One uses --oneline, one filters by file واحد يستخدم --oneline وآخر يرشّح بملف
- A blame followed through to the commit message blame متابَع حتى رسالة الـcommit
- A sentence on whether the message actually helped جملة عمّا إذا كانت الرسالة نافعة فعلًا