This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Practical Git: Format commit history with git log arguments

2:00 Tools lesson by

When running the git log command, we can pass in options as arguments to format the data shown for each commit. In this lesson, we show how to use the oneline, decorate, graph, stat, and p options with git log.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

When running the git log command, we can pass in options as arguments to format the data shown for each commit. In this lesson, we show how to use the oneline, decorate, graph, stat, and p options with git log.

In our command line, we're inside of a directory called Utility Functions, which is a git repository. When using the git log command, we can pass in arguments to tell our commit how we want them to be formatted.

The One Line option will condense our commits to a single line. We can see that we have the commit ID, as well as the commit message. The Decorate option will display all references for our commits. Here, we see new output in our log that shows the refs for this commit.

The Graph option will display an ask-er graph of the branch structure of each commit. We can see, for example, that this commit right here was branched off of master, and that it was merged back in right here.

The lower-class p option stands for patch, and shows us the changes made in each commit. For example, this commit right here, right below it, we can see that the thing that was changed is this line where this G was added to this regular expression.

The Stat option shows us the number of insertions and deletions for each commit change. Whenever a line is modified, it counts as an insertion or deletion. For this commit right here, we have seven insertions on the git ignore file. For this commit right here, we have 13 deletions, the read-me file, three insertions in the git random number file, as well as the total summary of the stat changes on the line below.

We can also compose all of these options together to format our commits. For example, we can pass the One Line option alongside the Graph option to get a condensed graph of our branch structure.

You can compose these options in any order that you'd like. For example, we can say that we want the statistics for each commit, and we also want the condensed version of each of the commits. If we run that, we get the condensed version of each commit, as well as the statistics for the commit.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?