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
One entry per commit, newest first. The long string is the commit's full identifier; the first seven characters are enough to refer to it. Press q to leave — it opens in less, from lesson 5 of the terminal course.

The forms worth knowing

CommandShows
git log --onelineOne line per commit — the one you will use most
git log --oneline --graphThe same, with branches drawn beside it
git log -5Only the last five
git log --statWhich files each commit touched, and by how much
git log -pThe full diff of every commit
git log -- index.htmlOnly 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
This is where last lesson's advice pays off. Read it as a list of sentences: if each line tells you what happened, the history is doing its job. Run the demonstration for the two commands that answer real questions rather than just listing.

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.

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.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. Which command tells you who last changed a particular line?

2. What does HEAD~1 mean?

3. Why do vague commit messages hurt most at this lesson?

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 جملة عمّا إذا كانت الرسالة نافعة فعلًا
How do you want to submit? / كيف تريد التسليم؟