Git is one of the well-known repositories for version control systems and used widely among programmers to keep an eye on the changes being performed regularly. Sometimes, it is observed that fetching the history does not fulfill the purpose of it; so, you need to filter the content accordingly. Git provides this facility with its git log command; git log is used to display the content from history by filtering it according to the options provided.
If you have a long list of commits and you want just basic information about commits; then the git log command provides a one line display of every commit. We have prepared this post to demonstrate the usage of git log command to get the output of commit in one line only: Let’s start this guide from general usage of git log followed by our targeted area:
Importance of git log
Git log command is one of the key contributors for git to make it a better choice for version control projects. The changes are committed frequently and the information about those commits is stored in history. Git log command is used to fetch the history and retrieve the information related to those commits. Git command offers to get the information related to commits by filtering the content as per the requirement of the user. For instance, if you want to filter the commits performed by specific authors; you just have to input the name of the author with the git log command instead of going through all the commits and then looking for that author manually.
How to use git log
The general application of git log is specified by the syntax written below:
git log [<options>] [<revision range>] [[—] <path>]
The option in this command refers to the output pattern of the log command; and revision range is specified to get the list of commits between two revisions and the path is specified get the log content for that file only:
We have added a GitHub project to check the commits of that project: use any of the command mentioned below to print all the commits of the project in detail:
Both the commands will display the detailed information about the commits: You will notice a multi-page output of this command that indicates the following information: unique hash of commit, time/date of that commit and author name and email.
How to use git log to print one line only
As the general execution of git log command gives detailed information about commits; but it may sometime be irritative due to long list of commits. If you want to get limited information that works for you then you can use “oneline” option of git command that prints only one line information about commits. This “oneline” property is based on two options of git log command: that are “–pretty=oneline” and “–abbrev-commit”:
To highlight the difference, we have executed both options by issuing the command mentioned below:
The “–pretty=online” option prints the one-line format of commits but does not support short form of sh: the following command can be used to trigger it:
$ git log –pretty=online
<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/1-7.jpg" data-lazy- height="308" src="data:image/svg xml,” width=”852″>
The “–abbrev-commit” prints commit with all information but only hash of each commit is in short form; use the command mentioned below to execute this option:
$ git log –abbrev-commit
<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/2-7.jpg" data-lazy- height="403" src="data:image/svg xml,” width=”726″>
The above two options are merged to get the result in a single option with git log command: execute the command mentioned below to get the result of above two commands in a single command only:
<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/3-7.jpg" data-lazy- height="272" src="data:image/svg xml,” width=”849″>
The output shows that only important information about commit is provided that includes the short hash of commit and name of that commit.
The computing technology is changing day by day to make it more competent in this revolutionary environment. These changes can be in the form of software invention or the hardware too and upgrading them also lies in this phenomenon. Millions of projects are maintained by the organizations working in the computer industry and these projects encounter addition of source code on a daily basis; so, the companies prefer to use a version control system to keep track of the changes. A well-known open-source software git supports version control access to manage such projects and the changes are committed and tracked to keep the previous versions. In this guide, we have demonstrated the use of Git log command to print the one-line information of commits. However, the detailed information about commits can also be attained with the help of this command.