This blog will illustrate the method of getting the commit history for just one Git branch.
How to Get Just One Branch Commit History?
To get the commit history for just one Git branch, first, launch the Git terminal and view the list of existing Git local branches. Then, select any one branch and switch to it. Next, run the “$ git log” command and add the dot “.” after space to get the whole Git Branch to commit history. However, to get a commit history by specifying the range, execute the “$ git log <range>” command.
Let’s check out the implementation of the above-provided scenario!
Step 1: Launch Git Bash Terminal
First of all, search for “Git Bash” using the Startup menu and launch it:
Step 2: List Git Branches
To list the existing Git local branches, execute the “git branch” command:
Here, the list of all local branches will be displayed. Select one branch to get its commit history. For instance, we want to get the commit history of the “dev” local branch:
Step 3: Switch to Target Branch
Run the “git switch” command with a particular Git local branch name and switch to it:
Here, the “dev” is our existing Git local branch:
Step 4: Get Particular Branch Commit History
To get the commit history of the current working branch, write out the provided command:
As you can see in the listed output, all the commit history of the current “dev” local branch is displayed:
Now, let’s check out another method.
How to Get Just One Branch Commit History With Particular Range?
You can also get the commit history of the Git single branch with a range by specifying the number of commits you want. For this purpose, execute the below-provided command:
Here, the “-1” is the range which means that we want to get the most recent commit:
Another example is executing the “git log” command with the “-2” range, which will get the last two Git commits of the particular Git branch:
Below output shows the history of the recent two commits:
That’s it! We have demonstrated the method to get the commit history for just one branch with and without range.
Conclusion
To get the commit history for just one Git branch, first, launch the Git terminal and view the list of existing Git local branches. Select any one local branch and switch to it. Next, execute the “$ git log .” command to get the whole Git to commit history. By specifying the range, you can also get a commit history according to your requirements. For this purpose, run the “$ git log <range>” command. This blog explained the procedure of getting the commit history for just one Git branch.