Git

How do I Run git log to See Changes Only for a Specific Branch?

Developers make many changes in their projects during the development phase. Those changes are saved in the log history. So, when they check the Git log, it displays the commits of all branches. Sometimes, users want to view some changes in a desired branch. However, it becomes hard to view a specific branch’s changes because so many commits are in the repository. In this situation, various Git commands can be utilized to view changes only for a specific branch.

How to Run the “git log” to View Changes Only for a Specific/Particular Branch?

To see the changes only for a specific branch, the “git log” command can be used in different ways, such as:

Method 1: View Brief Changes of Specific Branch

To view only a few changes like commit hash, and commit message of the specific branch, utilize the “git log” command along with the desired branch name and the “–oneline” option:

$ git log --oneline master

Here, the “–oneline” option is used to list the commits in each line.

The below screenshot displays the current position of HEAD, short commit id, and commit messages of the “master” branch:

Method 2: View Brief Changes of Specific Branch in Graph

Utilize the “–graph” and “–decorate” options with the previously used command to view the brief changes of a particular branch in the form of a graph:

$ git log --graph --decorate --oneline master

Here, the “–graph” and “decorate” flags are used to display the output in graph format:

Method 3: View Detailed Changes of Specific Branch

To view the detailed changes including full commit id, commit message, HEAD pointer, author detail, date, and time of the specific branch, write out the following command along with the desired branch name:

$ git log master .

Method 4: View Detailed Changes of Specific Branch in Graph

Execute the below-stated command to view the detailed changes of the specific branch in a graph:

$ git log --graph --abbrev-commit --decorate --first-parent master

Here:

  • –abbrev-commit” option is used to limit the commit id length.
  • –first-parent” flag is used to display only the first parent of each commit and ignore all other parents.

The output will display the short commit id, HEAD pointer, commit message, author details, date, and time information:

Method 5: View Changes of Particular Branch With Specific Query

To view only changes which are done by a particular user in a specific branch, type out the following command and specify the branch and author name:

$ git log master --author='Laiba Younas'

Here, the “–author” option is used to display the changes that were made by a particular author.

It can be seen that the output print out the changes made by author “Laiba Younas”:

That was all about viewing changes only for a specific branch.

Conclusion

Multiple commands can be used to see the changes only for a specific branch, such as the “git log –oneline <branch-name>” command to view brief changes and the “git log <branch-name> .” command to view the detailed changes in a particular branch. Furthermore, these same commands can be used with “–graph, –decorate”, “–abbrev-commit”, and “–author” options to customize the output. This article described different methods to see changes only for a specific branch.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.