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 439537a68f9823f85014ad8913799e2457f53319
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Wed Sep 10 13:14:09 2014 -0400

    Added a comment

commit 5e8d3ced0df8f8cef2abd824354f5dc66ace97b6
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Wed Sep 10 13:14:09 2014 -0400

    Added a default value

commit 9d5feaa52702c41a7ca58ea2f64b5156d5e7fb8e
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Wed Sep 10 13:14:09 2014 -0400

    Using ARGV

commit 7e5c12dc7dd9fbf2a8664a869bfa29d7504f734c
Author: Jim Weirich <jim (at) edgecase.com>
Date:   Wed Sep 10 13:14:09 2014 -0400

    First Commit

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

One Line Histories 01

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
439537a68f9823f85014ad8913799e2457f53319 Added a comment
5e8d3ced0df8f8cef2abd824354f5dc66ace97b6 Added a default value
9d5feaa52702c41a7ca58ea2f64b5156d5e7fb8e Using ARGV
7e5c12dc7dd9fbf2a8664a869bfa29d7504f734c First Commit

Controlling Which Entries are Displayed 02

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 03

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 04

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
* 439537a 2014-09-10 | Added a comment (HEAD, master) [Jim Weirich]
* 5e8d3ce 2014-09-10 | Added a default value [Jim Weirich]
* 9d5feaa 2014-09-10 | Using ARGV [Jim Weirich]
* 7e5c12d 2014-09-10 | 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 05

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

Table of Contents