Git

How Do I Check Git Logs?

How Do I Check Git Logs?
Sometimes, when you have cloned a repository or created various commits using an existing commit history, you would want to look at all commits history to view what has happened before. To display all commit history, you can check the Git log, a very useful tool that allows you to view all details about the previous commits that have been performed in a certain project. The simplest log command displays the commits history that leads up to the current state of the checked-out branch. All commits are displayed in reverse chronological order, which means you can view the recent commits first.

This article will give you a demo on how to check or view Git logs using Ubuntu 20.04 system. All the below-given examples we have taken are from a simple Git project called 'simplegit'. First, you need to get this project. Therefore, you have to open the 'Terminal' application by pressing 'Ctrl + Alt + t' and execute the following command to clone the 'simplegit' repository on your system:

$ git clone https://github.com/schacon/simplegit-progit

Viewing Git Commits Logs

You can view the commit history in the Git log by using the following command:

$ git log

As we have mentioned above, all most recently occurred commits will be displayed first.

You can see in the above-displayed image the 'git log' command list commits with the author's name along with the email address, date, and the commit message.

Git log command options

Several options are available, which you can use with the 'git log' command to display the same result that you are searching for. Below, we have mentioned some options that are most popular related to the git log command.

Display recent commits

The best option -p that is available about committed logs is the patched output, which limits the displayed log to the specified number 'n'. It will limit the output and display the number of commits that most recently occurred. For example, we want to display only 2 recent commits log entries. Therefore, you have to run the following command:

$ git log -p -2

Display each commit log summary

You can also display the complete summary of each commit with the 'git log'. For example, you want to display the stat of each commit, then you can use the '-stat' option with the 'git log' command as follows:

$ git log -stat

As you have noticed from the above output, the -stat option will also print the details about the modified files, the number of files added or removed, and display the files that have been changed after each commit entry. Moreover, a complete summary will be displayed at the end of the output.

Display each commit log in one line format

The -pretty option is useful for changing the output format. If you want to display each commit value in just one line, then by using the following command, you can print each commit log in a single line:

$ git log --pretty=oneline

Display customized output of Git log

Using the format option, you can specify your output log format. This 'format' option is useful, especially when you want to create output for machine parsing. Using the following format specifiers, with format option, you can generate customize 'git log' output:

$ git log --pretty=format:"%h - %an, %ar : %s"

You can explore more options related to the 'git log'. Here, we have mentioned the following options that will help you in the future:

Options Description
-p It displays the patch introduced with each commit log.
-stat It displays the complete summary of each commit.
-shortstat It only shows you the inserted, deleted, and modified lines.
-nameonly It shows a list of the names of files that have been updated after the commit detail.
-name-status It shows the information of the affected files with added, updated, and deleted files details.
-prety Shows output in the specified format
-oneline Shows output in just a single line
-graph Shows the ASCII graph of merge history and branch
-relative-date Using this option, you can use the relative date like 3 weeks ago instead of specifying the full date format.

You can get more help from the man pages of 'git log'. Type the following command to display the man page:

$ git help log

We have discussed how to view Git commits log on Ubuntu 20.04 system in this article. We have also listed and explained different options that you can use with the 'git log' command.

Comment utiliser AutoKey pour automatiser les jeux Linux
AutoKey est un utilitaire d'automatisation de bureau pour Linux et X11, programmé en Python 3, GTK et Qt. En utilisant ses fonctionnalités de script e...
Comment afficher le compteur FPS dans les jeux Linux
Les jeux Linux ont reçu une impulsion majeure lorsque Valve a annoncé la prise en charge de Linux pour le client Steam et leurs jeux en 2012. Depuis l...
Comment télécharger et jouer à Civilization VI de Sid Meier sur Linux
Présentation du jeu Civilization 6 est une version moderne du concept classique introduit dans la série de jeux Age of Empires. L'idée était assez sim...