lab 10 History
Goals
- Learn how to view the history of the project.
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 9efd33e5865fefea92e4fd5bc8c9485f262b5f07 Author: Ismail Dhorat <ismail@codiez.co.za> Date: Sun Oct 6 14:26:10 2013 +0200 Added a comment commit 8b9a1c64b666fac921c559c2364acd93bbab01e5 Author: Ismail Dhorat <ismail@codiez.co.za> Date: Sun Oct 6 14:26:10 2013 +0200 Added a default value commit f6f4d6b8b4ff7f4608670b43f499e1fa68cf2844 Author: Ismail Dhorat <ismail@codiez.co.za> Date: Sun Oct 6 14:26:10 2013 +0200 Using ARGV commit f98d857fee9fbc148c4e21f81c937106991e6d62 Author: Ismail Dhorat <ismail@codiez.co.za> Date: Sun Oct 6 14:26:10 2013 +0200 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 9efd33e5865fefea92e4fd5bc8c9485f262b5f07 Added a comment 8b9a1c64b666fac921c559c2364acd93bbab01e5 Added a default value f6f4d6b8b4ff7f4608670b43f499e1fa68cf2844 Using ARGV f98d857fee9fbc148c4e21f81c937106991e6d62 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=ismail
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 * 9efd33e 2013-10-06 | Added a comment (HEAD, master) [Ismail Dhorat] * 8b9a1c6 2013-10-06 | Added a default value [Ismail Dhorat] * f6f4d6b 2013-10-06 | Using ARGV [Ismail Dhorat] * f98d857 2013-10-06 | First Commit [Ismail Dhorat]
Let’s look at it in detail:
--pretty="..."
defines the format of the output.%h
is the abbreviated hash of the commit%d
are any decorations on that commit (e.g. branch heads or tags)%ad
is the author date%s
is the comment%an
is the author name--graph
informs git to display the commit tree in an ASCII graph layout--date=short
keeps the date format nice and short
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.