Git

Find Which Commit is Currently Checked out in Git

On Git, developers modify source code locally and add those changes to the local repository to push them to the remote repository. Sometimes, they need to find out what’s up with the project or which changes have been added recently. So, Git allows them to view the latest commits and all the added changes.

This write-up will discuss the methods of finding which Git commit is currently checked out.

How to Find Which Git Commit is Currently Checked out?

Git provides different commands to view which commit is currently checked out, such as:

Method 1: Find Which Commit is Currently Checked out in Git Using the “git show” Command

To find which particular Git commit is currently checkout, run the “git show” command along with the “-s” flag to only display the most recent commit history:

$ git show -s

As you can see in the below-provided output, all the information of the latest commit, including the commit message, the commit hash, and the position of HEAD, has been displayed:

If developers need to view the SHA-hash, HEAD position, and commit message in one line, they can utilize the “git show” command with the “–oneline” and “-s” options, as follows:

$ git show --oneline -s

Method 2: Find Which Commit is Currently Checked out in Git Using the “git log” Command

In order to find the detailed information of the currently checked-out commit, run the “git log” command along with the “-1” option:

$ git log -1

It can be observed that the details of the commit where HEAD pointing have been displayed:

The “git log” command can also be used with the “–oneline” option to view the latest commit information in one line:

$ git log -1 --oneline

Method 3: Find Which Commit is Currently Checked out in Git by Using the “git rev-parse HEAD” Command

To get the full SHA-hash value of the current checkout commit, execute the given-below command:

$ git rev-parse HEAD

The below output displayed the complete id of the latest commit:

We have described the different methods of finding which Git commit is currently checked out.

Conclusion

The “git show -s” or “git log -1” commands are used to find the latest commit with detailed information. If you want to view the current checkout commit in one line, the “git show –oneline -s” or “git log -1 –oneline” commands can be executed. Furthermore, the “git rev-parse HEAD” command assists in viewing the full SHA-hash value of the latest commit. This write-up discussed the methods to find which Git commit is currently checked out.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.