Skip to main content

Using Git

Check Git Commit History

Learn to quickly check the commit history in git.

Want to check the git commit history? Simply execute the git log command and it will bring the history of all the commits made on your current branch:

git log
list git commit history

Want more information? I got you.

How to check Git commit history

You can use the git log command in 3 ways to check the commit history:

  • git log: it will show you the history of the current branch.
  • git log <branch-name>: it allows you to target a branch specifically and will show you the history of that specific branch.
  • git log <file-path>: it reveals the history of a specific file.

In simple terms using the git log command, you can specify various aspects of a git repository and get the desired results.

Show the commit history of the current branch

To show the history of the current branch, all you have to do is execute the git log command without any additional flags:

git log 
Show the commit history of the current branch

But for some users, the output may include the commit history of the other repositories as well (I'm coming to the reason in a minute):

Diffrent branches are shown while using git log command

In the above image, you can see that there's a commit of the MyRepo branch even when I'm on the LHB branch and the reason is simple.

While creating and switching to the new branch, you must have used the git checkout -b MyRepo. The main culprit here is the -b flag which carries the files of the previous branch resulting in a history containing information about the parent branch as well.

Show the commit history of a specific branch

To display the history of a specific branch, all you have to do is append the name of the branch to the git log command as shown here:

git log <branch-name>

For example, if I want to see the history of the IF branch, then I will be using the following command:

git log IF
Show the commit history of a specific branch in git

Show the commit history of a file

If you want to target a file to check its commit history, then you can either append the file path or file name to the git log command as shown:

git log <filename or path to file>
Check the commit history of a file

GitHub is real fun 😄

I personally think that GitHub is where the true version of controlling starts as you can share and contribute to the entire world.

And if you are a student and just getting started, then here's how to create a rockstar student GitHub profile:

7 Tips to Make a Rockstar Student Developer GitHub Profile
Time to enhance the look and feel of your boring default GitHub profile with these tips and suggestions.

Also, if you are using VSCode, here's how to connect to GitHub from the VSCode itself:

How to Connect GitHub to VS Code [Step by Step]
Take your coding experience to the next level of ease by integrating GitHub into VS Code.

I hope you will find this guide helpful.

Sagar Sharma