Basic

Reading your own history

git log used to look like a wall of numbers to me. Really just a timeline of everything you have done, read top to bottom.just a timeline of everything you have done, read top to bottom.

What you will see

abc5678 break login Date: now break login login.py | 1 insertion(+), 1 deletion(-)

About 2 min of reading

Quick check

Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.

Try It

The command that turned a wall of numbers into a readable timeline. Let me make a few commits, read them back, and then dig one specific one out of a pile.

1

Take the commits I already made earlier this lesson: one called "Add login", one that broke it. git log opens the whole timeline from newest to oldest, with author, date, and message on every line.

git log

Before you run it, say out loud what it will print. Then open the answer.

What it prints
commit abc5678... Author: You Date: now break login commit abc1234... Author: You Date: now Add login
It fills the screen fast. Press the up arrow to scroll and q to quit. The most recent commit is always at the top.
2

Squeeze every commit down to a single line so the whole thing fits. Add --oneline and it stops looking like a wall of numbers and reads like a list. This is the version I look at 90% of the time.

git log --oneline

Before you run it, say out loud what it will print. Then open the answer.

What it prints
abc5678 break login abc1234 Add login
3

See where the branches actually went. --graph draws the branches as ASCII lines so you can spot where things merged and split, instead of reading hashes and guessing. Stack it with --oneline and both fit in one glance.

git log --oneline --graph

Before you run it, say out loud what it will print. Then open the answer.

What it prints
*-abc5678 break login * abc1234 Add login
The graph is ASCII, not pretty. It is enough to see the line move forward and branch, which is what tells you a commit landed somewhere you did not mean.
4

Jump straight to a change without scrolling back through everything. --grep searches commit messages, so I look for anything that touched the word "login", years later, it still finds it.

git log --oneline --grep="login"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
abc5678 break login abc1234 Add login
grep only matches the message, not the code inside a commit. If the message says "fix" but the file has login, this search will not see it, that is when you switch to --author next.
5

Find work by the person who made it. --author="You" shows only the commits tagged to me, which separates my commits from a teammate's the same way grep separated messages. Combine both to dig straight to one change.

git log --oneline --author="You"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
abc5678 break login abc1234 Add login
6

The thing that makes a hash a real fingerprint. Every commit stores its author, date, message, and the parent commit. The hash is computed from all of that, so it can never change without rewriting the commit, which is exactly why the hash tells you a commit is trustworthy.

git log --oneline --stat

Before you run it, say out loud what it will print. Then open the answer.

What it prints
abc5678 break login Date: now break login login.py | 1 insertion(+), 1 deletion(-)

Data Flow

Git walks the commit chain from HEAD toward the beginning, printing each commit as it goes.
1 Start at HEAD
↓
2 Print the current commit
↓
3 Move to its parent commit
↓
4 Repeat until the first commit
↓
5 Stop at the root
Why this works
What each commit holds

Every commit is a tiny package containing:

  • A unique hash (a SHA-1 code)
  • The author's name and email
  • The date and time
  • The message
  • The parent commit's hash

The hash is computed from all of that, so it can never change without rewriting the commit. That is what makes a hash a trustworthy fingerprint.

Flags that make it readable
FlagDoes
--onelineOne line per commit
--statFiles changed in each commit
--graphDraw the branch structure
--allShow commits on every branch

Stack flags together. git log --oneline --graph --stat gives you the full story in a compact form.

Examples

The plain timeline

git log

This lists every commit from newest to oldest, with author, date, and message. It fills your screen fast, so scroll with the arrow keys and press q to quit. The most recent commit is always at the top.

Make it fit the screen

git log --oneline --graph

--oneline squeezes each commit to one line. --graph draws the branches as ASCII lines so you can actually see where things merged and split. Together they turn the wall of numbers into something you can read in ten seconds.

Find the commit you are looking for

git log --grep="login"
git log --author="Ada"

--grep searches commit messages, --author filters by who made them. Combine them (--grep="login" --author="Ada") and you can dig straight to a specific change years later.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Before I press enter
Previous Lesson
Before I press enter
Next Lesson
Letting other people in
Letting other people in →