Viewing the Commit History
After you have created several commits, or if you have cloned a repository with an existing commit history, you’ll probably want to look back to see what has happened. The most basic and powerful tool to do this is the
git log command.
When you run
in your project, you should get output that looks something like this:
$ git log
By default, with no arguments,
git log lists the commits made in that repository in reverse chronological order. That is, the most recent commits show up first. As you can see, this command lists each commit with its SHA-1 checksum, the author’s name and e-mail, the date written, and the commit message.
A huge number and variety of options to the
git log command are available to show you exactly what you’re looking for. Here, we’ll show you some of the most-used options.
One of the more helpful options is
-p, which shows the diff introduced in each commit. You can also use
-2, which limits the output to only the last two entries:
git log -p –2
If you like to use a more graphical tool to visualize your commit history, you may want to take a look at a Tcl/Tk program called
gitk that is distributed with Git. Gitk is basically a visual
git log tool, and it accepts nearly all the filtering options that
git log does. If you type
gitk on the command line in your project, you should see something like
You can see the commit history in the top half of the window along with a nice ancestry graph. The diff viewer in the bottom half of the window shows you the changes introduced at any commit you click.
I use Bitbucket; I find looking at diffs between changes is also very effective in a browser.
Thank you for listening. Brian.