Lab 8: Git View History of the Repository

In this tutorial I will show you how to view the history of the project. You could use the git log command to get a list of what changes have been made in the repository. Execute the command:

git log

And see the following output.

git log

It list all the commits you have made to the repository so far. You can control how exactly the history is displayed. The one line format is:

git log --pretty=oneline

And the output would be similar to:

git log in one line

Controlling What is Displayed

There are a lot of options for selecting what is displayed in the log.

git log --pretty=oneline --max-count=2
git log --pretty=oneline --since='10 minutes ago'
git log --pretty=oneline --until='10 minutes ago'
git log --pretty=oneline --author=<your name>
git log --pretty=oneline --all

See man git-log for all the details.

Popular Log Format

One of the popular log formats is:

git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short

It outputs the log in the following format.

Git fancy log format

Lets take a look at all the options we have used.

  • --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 content has been helpful to you?

Thanks for contributing!

Yes No