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 dc44f2e4c830403ed7da3988e94dd1d97160c7b4
Author: Ismail Dhorat <ismail@codiez.co.za>
Date: Sun Oct 6 14:34:53 2013 +0200
Added a comment
commit 5ec54fda831fb596d947a3d987247be2c94136b4
Author: Ismail Dhorat <ismail@codiez.co.za>
Date: Sun Oct 6 14:34:53 2013 +0200
Added a default value
commit e606a20c1941fbe4f544c58df0a2f03c94d5ce6c
Author: Ismail Dhorat <ismail@codiez.co.za>
Date: Sun Oct 6 14:34:53 2013 +0200
Using ARGV
commit 5d95e74af5a1ea8a4478239b2ca665d12c42b7a1
Author: Ismail Dhorat <ismail@codiez.co.za>
Date: Sun Oct 6 14:34:53 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 dc44f2e4c830403ed7da3988e94dd1d97160c7b4 Added a comment 5ec54fda831fb596d947a3d987247be2c94136b4 Added a default value e606a20c1941fbe4f544c58df0a2f03c94d5ce6c Using ARGV 5d95e74af5a1ea8a4478239b2ca665d12c42b7a1 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 * dc44f2e 2013-10-06 | Added a comment (HEAD, master) [Ismail Dhorat] * 5ec54fd 2013-10-06 | Added a default value [Ismail Dhorat] * e606a20 2013-10-06 | Using ARGV [Ismail Dhorat] * 5d95e74 2013-10-06 | First Commit [Ismail Dhorat]
Let’s look at it in detail:
--pretty="..."defines the format of the output.%his the abbreviated hash of the commit%dare any decorations on that commit (e.g. branch heads or tags)%adis the author date%sis the comment%anis the author name--graphinforms git to display the commit tree in an ASCII graph layout--date=shortkeeps 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.