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 59992ce6a7cd58a6c80189b137964eea3d1df17d Author: Halle Bot <halle (at) operationspark.org> Date: Thu Jun 27 14:45:18 2019 -0500 Added a comment commit 20a6c79e9355f7f5fc8aae379a7fdee0f625c955 Author: Halle Bot <halle (at) operationspark.org> Date: Thu Jun 27 14:45:18 2019 -0500 Added a default value commit 6915d417a8ab6ac71184cde8f5b068026af43d08 Author: Halle Bot <halle (at) operationspark.org> Date: Thu Jun 27 14:45:17 2019 -0500 Using process.argv commit 284070da97229f2f8ff812608318ba03412205b5 Author: Halle Bot <halle (at) operationspark.org> Date: Thu Jun 27 14:45:17 2019 -0500 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 59992ce6a7cd58a6c80189b137964eea3d1df17d Added a comment 20a6c79e9355f7f5fc8aae379a7fdee0f625c955 Added a default value 6915d417a8ab6ac71184cde8f5b068026af43d08 Using process.argv 284070da97229f2f8ff812608318ba03412205b5 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 * 59992ce 2019-06-27 | Added a comment (HEAD -> main) [Halle Bot] * 20a6c79 2019-06-27 | Added a default value [Halle Bot] * 6915d41 2019-06-27 | Using process.argv [Halle Bot] * 284070d 2019-06-27 | First Commit [Halle Bot]
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
Both gitx
(for Macs) and gitk
(any platform) are useful in exploring log history.