Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (29.3k points)

What command can I use to print out the commit id of HEAD?

This is what I'm doing by hand:

$ cat .git/HEAD

ref: refs/heads/v3.3

$ cat .git/refs/heads/v3.3


But I need a script that can reliably pipe the output of some command to a text file such that the text file contains exactly the commit id of HEAD (nothing more or less, and not just a ref). Can anyone help?

1 Answer

0 votes
by (50.2k points)

Use the command that will help you to display head commit id for that you could use:

git rev-parse HEAD

For the short version:

git rev-parse --short HEAD


Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories