Skip to content

lab 9 History

Goals

Getting a listing of what changes have been made is the function of the git log command.

Execute:

git log

You should see …

Output:

$ git log
1c410c657e8ba922365b4f5c5b5f42f60bb08798 Add a comment
0bf384cf2bd2f1727489ebaf16ff660b6c69ded4 Display user input
31c394510172ee6f68cc3769f5d16d915040f95c Add some content
aa5d425d482360ebc98af5ba3ee2c9c8baaa98f6 First Commit

Here is a list of all four commits that we have made to the repository so far.

One Line Histories

You have a great deal of control over exactly what the log command displays. I like the one line format:

Execute:

git log --pretty=oneline

You should see …

Output:

$ git log --pretty=oneline
1c410c657e8ba922365b4f5c5b5f42f60bb08798 Add a comment
0bf384cf2bd2f1727489ebaf16ff660b6c69ded4 Display user input
31c394510172ee6f68cc3769f5d16d915040f95c Add some content
aa5d425d482360ebc98af5ba3ee2c9c8baaa98f6 First Commit

Controlling Which Entries are Displayed

There are a lot of options for selecting which entries are displayed in the log. Play around with the following options:

git log --pretty=oneline --max-count=2
git log --pretty=oneline --since='5 minutes ago'
git log --pretty=oneline --until='5 minutes ago'
git log --pretty=oneline --author=<your name>
git log --pretty=oneline --all

See man git-log for all the details.

Getting Fancy

Here’s what I use to review the changes made in the last week. I’ll add --author=theophile if I only want to see changes I made.

git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago'

The Ultimate Log Format

Over time, I’ve decided that I like the following log format for most of my work.

Execute:

git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short

It looks like this:

Output:

$ git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
* 1c410c6 2023-08-21 | Add a comment (HEAD -> main) [Théophile Chevalier]
* 0bf384c 2023-08-21 | Display user input [Théophile Chevalier]
* 31c3945 2023-08-21 | Add some content [Théophile Chevalier]
* aa5d425 2023-08-21 | First Commit [Théophile Chevalier]

Let’s look at it in detail:

This is a lot to type every time you want to see the log. Fortunately we will learn about git aliases in the next lab.

Other Tools

Both gitx (for Macs) and gitk (any platform) are useful in exploring log history.