This write-up will explain the methods of getting the commit id of the head of Master in Git.
How to Get/Retrieve the Commit id of the Head of “master” in Git?
To get/retrieve the commit id of the head of “master”, various Git commands are available, such as:
Note: First, navigate to the master branch in order to get its commit id.
Method 1: Get Commit of Head of “master” Utilizing “git rev-parse HEAD” Command
Execute the below-provided command to get the commit id of the head of the master branch:
The given output displays the full SHA-hash value of the HEAD of the “master” branch:
Moreover, in order to get the short commit id, utilize the “–short” option with the previous command:
Here, the “–short” option shows the first seven digits of the commit id:
Method 2: Get Commit of Head of “master” Utilizing “git show HEAD” Command
In order to get the detailed information of the HEAD including the commit id, run the following command:
In the below-provided screenshot, the commit id of the HEAD, commit message, date, author, etc., can be seen:
Method 3: Get Commit of Head of “master” Utilizing “git log -1” Command
Type out the provided command to get the SHA-hash of the head of the master branch:
Here, the highlighted part is the commit id of the head of the “master” branch:
We have explained the various methods to get the commit id of the head of Master in Git.
Conclusion
Different Git commands are available to get the commit id of the head of the master branch in Git, such as the “git rev-parse HEAD” command is used for getting the full commit id, and the “–short” option with the same command is utilized to get the short SHA-hash value. Moreover, to get detailed information about the HEAD, the “git show HEAD” and “git log -1” commands can be used. This write-up explained the methods of getting the commit id of the head of master in Git.