Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a commit by its hash?

Tags:

git

I need to find a commit in Git by a given hash, SHA. For example, if I have the "a2c25061" hash, and I need to get the author and the committer of this commit.

What is the command to get that?

like image 973
Ghadeer Avatar asked Jan 05 '13 00:01

Ghadeer


People also ask

How do you get the hash of a commit?

We can obtain the hash using rev-parse . We can add the --verify flag to rev-parse to ensure that the specified object is a valid git object. It's especially help to use it --verify with a variable branch name. To obtain the shortened version of the hash, we can use the --short flag.

What is a commit hash?

The commit hash is an SHA-1 hash made up of a few properties from the commit itself. As mentioned above, it is a lot more complex than this post can go into, but understanding the fundamentals is a great first step. The git hash is made up of the following: The commit message. The file changes.

How do you get details of a commit?

`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.

How do I search for a commit in GitHub?

To search for a hash, just enter at least the first 7 characters in the search box. Then on the results page, click the "Commits" tab to see matching commits (but only on the default branch, usually master ), or the "Issues" tab to see pull requests containing the commit.


2 Answers

Just use the following command

git show a2c25061 
like image 134
2 revs, 2 users 50% Avatar answered Sep 28 '22 14:09

2 revs, 2 users 50%


git log -1 --format="%an %ae%n%cn %ce" a2c25061 

The Pretty Formats section of the git show documentation contains

  • format:<string>

The format:<string> format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \n

The placeholders are:

  • %an: author name
  • %ae: author email
  • %cn: committer name
  • %ce: committer email
like image 20
Greg Bacon Avatar answered Sep 28 '22 14:09

Greg Bacon