How to display metadata about single commit in git?

Git

Git Problem Overview


I'd like to parse meta information from git repository. I'd like to fetch a single information for a commit, as in

git log --pretty=format:%an HEAD^..HEAD

Problem is, this is not working for the first commit in repository.

git show --pretty=format:%an HEAD^..HEAD

is also close to what I want, except I'm not interested in parsing actual diff.

Any idea how to make git log work for the first commit or how to disable git show from showing commit content?

Or, is there any better way how to retrieve metadata about given commit?

Git Solutions


Solution 1 - Git

Supply the quiet option to show to suppress the diff.

git show --quiet HEAD

So for your example, author name:

git show --quiet --pretty=format:%an

Solution 2 - Git

git --no-pager show -s --format='%an <%ae>' COMMIT

(Taken from quora.com)

Solution 3 - Git

git log -n 1 --format='%an'

-n 1 restricts the log to a single commit.

Does the same as git show --quiet, although I prefer it a bit since it is documented on man git-log while --quiet is not documented on man git-show as of 2.17.

Also note that you can golf even better with show with the short form of --quiet:

git show -q --format='%an'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlmadView Question on Stackoverflow
Solution 1 - GitCB BaileyView Answer on Stackoverflow
Solution 2 - GitkopporView Answer on Stackoverflow
Solution 3 - GitCiro Santilli Путлер Капут 六四事View Answer on Stackoverflow