Skip to content

lab 10 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 7bf0bf17ab217ae2415f16aaddc55d0ee1d1db8e
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Fri Sep 28 08:58:08 2018 -0700

    Added a comment

commit 9cf3f21bb9edc52e1ce6e53f1fcf858ab1735ed7
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Fri Sep 28 08:58:08 2018 -0700

    Added a default value

commit 94e1b8b297708d99cab616317ecd0a59974a624e
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Fri Sep 28 08:58:08 2018 -0700

    Using ARGV

commit f656098a06281f1c2ebaf9f6a450e34dc1802e72
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Fri Sep 28 08:58:08 2018 -0700

    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
7bf0bf17ab217ae2415f16aaddc55d0ee1d1db8e Added a comment
9cf3f21bb9edc52e1ce6e53f1fcf858ab1735ed7 Added a default value
94e1b8b297708d99cab616317ecd0a59974a624e Using ARGV
f656098a06281f1c2ebaf9f6a450e34dc1802e72 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=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
* 7bf0bf1 2018-09-28 | Added a comment (HEAD -> master) [Jim Weirich]
* 9cf3f21 2018-09-28 | Added a default value [Jim Weirich]
* 94e1b8b 2018-09-28 | Using ARGV [Jim Weirich]
* f656098 2018-09-28 | 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.