Git log --oneline

Learn via video courses
Topics Covered

Overview

In this article, we are going to learn about git log one line. Before getting started with the topic, let us get a short overview of what is git log one line command is.

git log one line: The oneline is an option of the git log command. The main purpose of this command is to print a single commit in a single line as output when the git log command is executed using this option. Using this option, the commits are printed in a pattern - the commit SHA's initial 7 characters than the commit message.

So let us now begin with the main agenda of our article, git log one line.

Introduction to Git Log

One of the benefits of any version control system is all the updations or changes are been recorded by them. These stored data also consist of commits, updates, figuring out bugs, etc. which we can retrieve later. However, if we are unable to navigate them, then all these data will be of no use, and hence it is achieved by the git log command.

Using the git log command, we can review the history of everything that occurred in the repository. There are different options that we can use along with the git log command to get the history in a customized way. git log --oneside is one of the options of the git log command.

We can get the history of commits using the git log. Apart from that, a git log contains the below data :

  • A commit hash:, which is a checksum data of forty characters is produced by the SHA (Secure Hash Algorithm) algorithm. It is unique data.
  • Commit Author metadata : This consists of all the details of the authors like their email and name.
  • Commit Date metadata : It records the timestamps for the time the commit is made.
  • Commit title/message : It consists of the description of the commits, which is provided in the commit message.

One of the most often used git commands is git log. It is the Git command that is most helpful. You must run the git log command each time you wish to view the history. The state of the head and the most recent commits are both shown by the git log command's default output. It will be used for:

All the latest commits will be displayed by using this git log command. Consider the below output :

Output:

Introduction to git log

Explanation:

  • From the above output, it is clear that the git log command displays all the recent commits that have been made in the repository.
  • Every commit consists of some 40 characters unique number also known as sha-id, which is produced by the SHA algorithm.
  • We can also observe, the commit records consist of different information such as time, date, author, etc.
  • Along with checking the records of recent commits, we can perform different activities such as jumping, scrolling, quitting, and moving on the CMD (command line). If you want to scroll up or down the commits in the command line, you can just press j for scrolling down, k for scrolling up, Press the spacebar will scroll down by a complete page, and press q will exit the command line.

What is Git --oneline?

Now, you might have got a clear understanding of the git log command. However, the visuals of the commits history which is displayed as output is not much pleasing, and due to that, the result is bulky and it is difficult for the user to read the commit history. To fix that, we can use the --oneline option along with the git log command.

Now, the oneline is an option of the git log command. The main purpose of this command is to print a single commit in a single line as output when the git log command is executed using this option. Using this option, the commits are printed in a pattern - the commit SHA's initial 7 characters than the commit message.

We can use this command as follows :

Syntax:

Let us look at the syntax of the git log one line command

Thus, we can generally state that the --oneline option gives the following git log output :

  • Single commit on a single line
  • The initial 7 characters generated by the SHA algorithm
  • The commit message.

Output:

Consider the below output :

git oneline

Explanation:

From the above output, we can observe that every commit is supplied just on one line together with a seven-digit SHA number and commit message.

Example

Let us now look at a relevant example of the git log --oneline command, for more clear understanding.

Abstract:

Using the --pretty=oneline option along with the git log command, check the output.

Code:

Output:

example of git oneline

Explanation:

From the above output, we can observe that every commit is supplied just on one line together with a forty-digit SHA number and commit message.

It is not required to prepend the --pretty term to the oneline option, as there is a built-in alias for the command :

Code:

Output:

git oneline example

Explanation:

From the above output, we can observe that every commit is supplied just on one line together with a seven-digit SHA number and commit message.

Git Log --graph

The graphing feature is another cool feature of the git log command. We can get our logs of commits in the form of a graph using the --graph option along with the git log command. If you execute the git log command along with the --graph option, a graphical overview of the way a developer's different development pipelines have been merged and branched over time will be displayed as output.

It is quite impressive, the way the visuals of the commit history are done through a decidedly non-visual BASH shell or terminal window. Let us look at some additional interesting properties of the git log --graph command, and the way you can use it in the code.

Syntax:

Let us look at the syntax of the git log graph command

Output:

Consider the below output :

git log graph

The only issue with using the basic --graph option is that the wordiness of the log gets in the way. Hence, to fix that we can use this --graph option along with the --pretty oneline option in the git log command, in which the output will be in a much better format.

Code:

Output :

git log graph 2

Users can also execute the above command by not prepending the --pretty term to the oneline option.

Both parameters significantly increase the readability of the git log graph and enable the visually appealing presentation of newly generated and merged branches over time.

Graph All Git Branches

You can get all the branches of the repository in graphical format using the --all option along with the --graph option. You can also use the --decorate option along with this --graph option to other supplemental details such as author, commits, etc. in a much better color-coded and easy-to-read format.

Code:

Output :

Graph all git branches

Using only the git log command might be hectic for us sometimes, due to its messy formatting. Still, in case if you use all these 4 options along with the git log command, it will make your work very easy, and honestly, these 4 options are the only options you need at most with the git log command. You may use the phrase a dog to help you recall this combination :

  • a: --all
  • d: --decorate
  • o: --oneline
  • g: --graph

A Pretty Git Log Graph

There are multiple ways to format or design the git log command output, using the --pretty option along with the git log command, mostly when the custom string is used by the developer. For instance, when the %ad string is added as a parameter along with the pretty option, then all the dates of commit made will be attached with the branch and merge points in the git log graph output.

when the %h string is added as a parameter along with the pretty option, then a short commit hash will be displayed, and when the %s string is added as a parameter along with the pretty option, then the commit message will be displayed along with the git log graphs’ commit points.

Syntax :

If you want to get more pleasing visuals with the git log command, you can give your color code to the output commits and branches, you can do this using the git log graph call like the one that follows:

Code:

Output :

A pretty git log graph

Explanation:

In the above code, we can see that by using the %c as a parameter we can set the coloring code of output. Such as we have colored the commit hash with green color, the date with red color, and the message with yellow color.

With the help of the git log command, we can get an overview of the workflow and the commit history. And with the use of the --oneline option along with the git log command, we can fetch the output in a more formatted and customized way, which will seriously help us in saving our time while inspecting the Git commit history.

Conclusion

In this article, we learned about the git log one line. Let us recap the points we discussed throughout the article:

  • The oneline is an option of the git log command. The main purpose of this command is to print a single commit in a single line as output when the git log command is executed using this option.
  • Using this option, the commits are printed in a pattern - the commit SHA's initial 7 characters than the commit message.
  • Using the git log command, we can review the history of everything that occurred in the repository. There are different options that we can use along with the git log command to get the history in a customized way. git log --oneside is one of the options of the git log command.
  • The git log command consists of data such as 40 characters commit hash which is unique, Commit Author metadata which consists of all the details of the authors like their email and name, Commit Date metadata which records the timestamps for the time the commit is made, and Commit title/message which consists of the description of the commits, which is provided in the commit message.
  • The visuals of the commits history which is displayed as output is not much pleasing, and due to that, the result is bulky and it is difficult for the user to read the commit history. To fix that, we can use the --oneline option along with the git log command.
  • By using the --oneline option along with the git log command we get the output where every commit is supplied just on one line together with a seven-digit SHA number and commit message.
  • We can get our logs of commits in the form of a graph using the --graph option along with the git log command. If you execute the git log command along with the --graph option, a graphical overview of the way a developer's different development pipelines have been merged and branched over time will be displayed as output.
  • The only issue with using the basic --graph option is that the wordiness of the log gets in the way. Hence, to fix that we can use this --graph option along with the --pretty oneline option in the git log command, in which the output will be in a much better format.
  • You can get all the branches of the repository in graphical format using the --all option along with the --graph option.
  • You can also use the --decorate option along with this --graph option to other supplemental details such as author, commits, etc. in a much better color-coded and easy-to-read format.
  • Using only the git log command might be hectic for us sometimes, due to its messy formatting. Still, in case if you use all these 4 options along with the git log command, it will make your work very easy, and honestly, these 4 options are the only options you need at most with the git log command. You may use the phrase a dog to help you recall these options.
  • When the %ad string is added as a parameter along with the pretty option, then all the dates of commit made will be attached with the branch and merge points in the git log graph output.
  • When the %h string is added as a parameter along with the pretty option, then a short commit hash will be displayed.
  • When the %s string is added as a parameter along with the pretty option, then the commit message will be displayed along with the git log graphs’ commit points.
  • If you want to get more pleasing visuals with the git log command, you can give your color code to the output commits and branches, you can do this using the %C string as a parameter.
  • We have seen some relevant examples of the git log command along with the --oneline option for more clear understanding.