Skip to content

lab 11 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
commit 1dee7f9aea43849aaa80edbc7bc43e63eb6f5315
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Mon Oct 24 19:02:01 2022 +0000

    Tell user how many names they have

commit c72af6b9810f51d8315497fe97f2da83d4f9f80d
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Mon Oct 24 19:02:01 2022 +0000

    Rename variable to match its usage

commit 8cdd2cde2c9bd9044453a027178e76f44a7821da
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Mon Oct 24 19:02:00 2022 +0000

    Can specify multiple names

commit 28fe3964845c16ff89ac6793c4f9c91fde44f109
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Mon Oct 24 19:02:00 2022 +0000

    Added a comment

commit 15c7573dd7a7e91fca1db3a72da1ca4757c90137
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Mon Oct 24 19:02:00 2022 +0000

    Added a default value

commit 7d55044c68b2827a88297c1c44afc61792577352
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Mon Oct 24 19:02:00 2022 +0000

    Using ARGV

commit 91b926ef01fd87e82d603834821cab7c88877ed9
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Mon Oct 24 19:01:59 2022 +0000

    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
1dee7f9aea43849aaa80edbc7bc43e63eb6f5315 Tell user how many names they have
c72af6b9810f51d8315497fe97f2da83d4f9f80d Rename variable to match its usage
8cdd2cde2c9bd9044453a027178e76f44a7821da Can specify multiple names
28fe3964845c16ff89ac6793c4f9c91fde44f109 Added a comment
15c7573dd7a7e91fca1db3a72da1ca4757c90137 Added a default value
7d55044c68b2827a88297c1c44afc61792577352 Using ARGV
91b926ef01fd87e82d603834821cab7c88877ed9 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
git log --patch
git log -S "Hello"

See man git-log or git log --help for all the details.

Getting Fancy

Here’s what I use to review the changes made in the last week. I’ll add --author=jim 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
* 1dee7f9 2022-10-24 | Tell user how many names they have (HEAD -> main) [Jim Weirich]
* c72af6b 2022-10-24 | Rename variable to match its usage [Jim Weirich]
* 8cdd2cd 2022-10-24 | Can specify multiple names [Jim Weirich]
* 28fe396 2022-10-24 | Added a comment [Jim Weirich]
* 15c7573 2022-10-24 | Added a default value [Jim Weirich]
* 7d55044 2022-10-24 | Using ARGV [Jim Weirich]
* 91b926e 2022-10-24 | First Commit [Jim Weirich]

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.