Skip to content Skip to sidebar Skip to footer

what git command do you use to show the history of commits?

A git repository contains many commits depends on the projection job. Sometimes the git user needs to clone a repository with the existing commits and may require to know the previous git commit history. `git log` command is used to view the commit history and display the necessary data of the git repository. This command displays the latest git commits information in chronological social club, and the last commit will be displayed first. The dissimilar ways to view the commit history of the git repository by using the `git log` control have been explained in this tutorial.

Prerequisites:

Install GitHub Desktop.

GitHub Desktop helps the git user to perform the git-related tasks graphically. You can easily download the latest installer of this application for Ubuntu from github.com. You accept to install and configure this application after download to utilise information technology. You tin can as well check the tutorial for installing GitHub Desktop on Ubuntu to know the installation process properly.

Create a GitHub business relationship.

You will require to create a GitHub business relationship to cheque the output of the commands in the remote server.

Create a local and remote repository.

You have to create a local repository and publish the repository in the remote server to test the commands used in this tutorial. Go to the local repository folder to check the commands used in this tutorial.

View commit history:

The commit history tin be viewed in different ways by using the `git log` command. A local repository named bash has been used in this tutorial to test the commands used in this tutorial. Run the following control to view the commit history of the repository. The output will contain the commit SHA value, username and email of the writer, commit engagement and time, and the commit message.

The post-obit output shows that two commits accept been done in the electric current repository past the aforementioned author on the same date but at different times. Ii dissimilar commit SHA values accept been created for two different commits.

The commit history can be viewed based on the commit SHA value using the `git show` command. Run the following command to view the commit history of the given commit SHA.

$ git prove ab35d03c8f4f238fd94f0ec3abd533dbe0b5a352

The output shows the details of the commit history based on the particular commit SHA value. The other information such equally the filename, file fashion, index value, and the content of the committed file have displayed here. It helps the git user to identify the necessary commit that the user wants to alter or correct.

The -p or –patch option is used with the `git log` control to display the difference in each commit. The view of the log entries can be express by defining a specific number with this option. Run the following control to display the latest commit history.

The post-obit output will appear later on executing the higher up command. It looks like the previous output considering only ane commit history has been retrieved hither. When the multiple commit history is displayed past increasing the limit value, the departure between the commit history will be cleared.

The –stat pick is used with the `git log` command to brandish some country data with the commit history.

The following output shows that the .gitattributes file has been inserted in the initial commit. The bash-basic-tutorial.sh file has been inserted in the second commit of the repository with the other commit information.

The –online option of the `git log ` command displays the commit history in a single line with the brusk commit SHA value. When the repository contains many commits, the `git log` command will long. The output of all commit history tin be displayed in the short form by using the –online option that helps to view a large number of commit history properly.

The following output will appear after executing the higher up command. Here, the starting time 7 characters of the commit SHA value take displayed for each commit.

The –pretty is another option of `git log` to display the log output in various formats. This option tin can exist used by assigning different types of values, and the output of the command depends on the assigned value.  Run the post-obit command to view the commit history in the short form by assigning online for the –pretty option.

$ git log --pretty=oneline

The output of the above control is similar to the previous command except for the commit SHA value. Here, the total commit SHA value has displayed.

Many placeholders exist, which are defined by the character literals to format the log output. The log output can exist formatted co-ordinate to the user'southward requirement by defining the format with the proper cord value in the –pretty pick. Run the following command to print the commit SHA value in the curt form, the git username, and the commit message in the mode that has been defined in the cord. Here, %h is used to display the commit SHA value in the brusque form, %an is used to display the author's username, and %s is used to brandish the commit message.

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

The following output will appear later executing the higher up command.

Conclusion:

The commit history is an essential office of any git repository.  The git user tin get an idea about each commit of the repository by viewing the commit history and making the necessary modification. The different ways to view the commit history have been shown in this tutorial using a demo repository.

Near the author

I am a trainer of web programming courses. I like to write article or tutorial on various Information technology topics. I have a YouTube channel where many types of tutorials based on Ubuntu, Windows, Give-and-take, Excel, WordPress, Magento, Laravel etc. are published: Tutorials4u Assistance.

scottficy1957.blogspot.com

Source: https://linuxhint.com/view-the-commit-history-of-the-git-repository/

Post a Comment for "what git command do you use to show the history of commits?"