Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git command to display HEAD commit id?

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 6050732e725c68b83c35c873ff8808dff1c406e1 

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?

like image 848
Andrew Arnott Avatar asked Dec 28 '09 04:12

Andrew Arnott


People also ask

How can I see my head commit?

You can view your repository's heads in the path . git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch.

Which command we can use to check commit ID?

If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.

How do I display a commit?

The HEAD reference always points to the last commit of the current branch. Therefore, you can use git-show to display the log message and diff output of the latest commit.

What is the commit ID in git?

Commit IDs are unique SHA-1 hashes that are created whenever a new commit is recorded. If you specify a commit ID when adding a repository, Domino will always pull the state of the repository specified by that commit in a detached HEAD state.


1 Answers

Use the command:

git rev-parse HEAD 

For the short version:

git rev-parse --short HEAD 
like image 96
Randal Schwartz Avatar answered Sep 28 '22 20:09

Randal Schwartz