How to find a commit by its hash?
GitGit Problem Overview
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?
Git Solutions
Solution 1 - Git
Just use the following command
git show a2c25061
Solution 2 - Git
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
Solution 3 - Git
There are two ways to do this.
1. providing the SHA of the commit you want to see to git log
git log -p a2c25061
Where -p
is short for patch
2. use git show
git show a2c25061
The output for both commands will be:
- the commit
- the author
- the date
- the commit message
- the patch information