Git logs

Git logs: The main function of logs in Git is to show commit logs. It is generally used to list commits that are associated with the parent links from the given commits. They also exclude the reachable commits through the ^ sign in front of them. The default output will be delivered in reverse chronological order.

In general, a log can be assumed as a set of operations. The reachable commits from any given commits are added or subtracted from any given commit by placing ^ in front. The left-out commits are printed as an output. Thus, the various parameter paths can be limited which may vary. In a version control system, the changes are committed, bugs are figured out, and are seamlessly updated. But, these functions are useless if there is no record of these processes. This is where Git log comes into play. Log acts as a utility tool that reviews and records a history of everything that happens in a repository. Git log contains the following data:

* Commit hash: It is a checksum data encrypted by SHA algorithm.

* Commit date metadata: It is the timestamp for the commits.

* Commit author metadata: It stores information of user

* Commit title/message: It the commit overview for title/messages.

Let us now look at some types of Git log commands and their functions.

Basic Git log

$ git log

It is the most used and important command for checking out the logs of your repository. The logs may be different for different users. Therefore, it lists out all the recent commits made. If you closely observe after typing this command, you can see the unique identity of every single commit you may have made including date, time, author, and other details.

Note: Other details contain activities like scrolling or jumping to any commits. This can be done by other commands used to fetch them.

Git Oneline

The main function of oneline log in Git is to display commits per line. It is rolled out the characters of the SHA (Secure hash algorithm) commit along with the message.

$ git log --oneline

Therefore, oneline is used to:

* display one commit per line.

* display the characters of SHA.

* display the committed message.

Git log patch

This log command is generally used for changes made in a repository or it displays the modified changes in terms of location, removed, or added files. We can simply type the following commands to get the patch logs.

$ git log --patch

Or

$ git log -p

Git log Stat

As the name suggests, Git log stat command is to get the information of the modified changes. It is used to:

* get the modified files.

* the number of line removed or added anytime.

* the summary of changed records and the lines which are removed or added.

Git log graph

This command is used to visualize the commits in the form of graphical representation. Graphs are much easier to understand and by using this command you can visualize the rate of commits and other factors affecting your commits. To view this, we type the following commands.

 $ git log --graph
 $ git log --graph--oneline    // gives details in separate lines 

Refining commit history

One unique feature of Git constitutes the ability to filter out data in terms of time, date, author, and other factors. It helps you to figure out what exactly do you want from your logs. To get filtered data, let's slip into the commands in terms of:

Date and Time

To get logs based on date and time, Git provides you with a unique and specific command to filter the data in terms of it. The command is:

 $ git log --after= “yy-mm-dd”
 $ git log --after= “15 days ago” 

These commands need no explanation since it is quite easy to understand that one command will give commit details in terms of date and the other will the commit log after 15 days.

We can also get the commit logs by combining the above filter to find the logs that occurred between them. To do this, we type:

$ git log --after “2021-12-02” --before= “2020-12-02”

By Author

This command gives all the commits made by a user. The command for logs in terms of author is:

$ git log -author= “Kundan Pathak”

Or

$ git log -author = “[email protected]

By commit name/message

The data can also be fetched out and displayed using the commit names. If one doesn't remember the commit name, he can just check out from the commit history status and get the commit name. Now, if we want all the details of the commit by name/message, we type the following command

$ git log --grep= “Commit Message”