Autoplay

    Practical Git: Format commit history with git log arguments

    Trevor MillerTrevor Miller

    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.

    gitgit
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 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.

    00:11 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.

    00:30 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.

    00:45 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.

    01:02 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.

    01:30 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.

    01:43 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.

    Discuss

    Discuss