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:
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:
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:
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:
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:
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.