| by Arround The Web | No comments

How to Show Commit History for One Branch Using Git Log With Range

Git keeps the log history or all commit changes that are made in the projects file within a Git repository from the developer. Its users can check them whenever they need to, and this operation can be performed through “$ git log”. Moreover, users can also display a specific number of commit log histories by specifying the range.

This guide will provide the procedure of showing the commit history of Git one branch using the Git log command with range.

How to Show Commit History for One Branch Using Git Log With Range?

Suppose you want to show the two most recent commits log history. For this purpose, first, move to the Git directory. Then, display its content list. Open any file and update it. After that, utilize the “$ git log -2” command to show specific commits.

Let’s implement the above scenario through the provided steps!

Step 1: Launch Git Bash
Search and launch Git terminal with the help of the “Startup” menu:

Step 2: Navigate to Git Directory
Move to the “linux” Git directory using the “cd” command:

$ cd "C:\Users\nazma\Git\linux"

Step 3: Check Directory List
Next, execute the “ls” command to list the content of the current directory:

$ ls

Step 4: Update File
Open the “file2.txt” file by utilizing the provided command:

$ start file2.txt

As you can see, the “file1.txt” is opened in the Git default editor. Now, add some text, save it and exit the file:

Step 5: Commit Changes
Next, commit changes to the Git repository using the “git commit” command with the “-m” flag:

$ git commit -m "file2.txt updated"

Step 6: Check Log History
Now, we will check the commit history of Git repository:

$ git log -2

Here, “-2” indicates the range which means that we only want to display the history of the two most recent commits:

That’s it! We have offered the procedure of showing the commit history of Git one branch using the Git log command with range.

Conclusion

To show commit history for one branch using Git log with range, first, open up the Git terminal, and move to the Git directory. Then, list the whole content of the Git repository, open up any file and update it. Next, commit changes. Lastly, execute the “$ git log <range>” command with the range of commits for displaying their history. In this guide, we have demonstrated the method of showing the commit history of Git one branch using the Git log command with range.

Share Button

Source: linuxhint.com

Leave a Reply