如何在 git 中显示有关单次提交的元数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1828252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display metadata about single commit in git?
提问by Almad
I'd like to parse meta information from git repository. I'd like to fetch a single information for a commit, as in
我想从 git 存储库中解析元信息。我想为提交获取单个信息,如
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?
知道如何使 git log 为第一次提交工作或如何禁用 git show 显示提交内容吗?
Or, is there any better way how to retrieve metadata about given commit?
或者,有没有更好的方法来检索有关给定提交的元数据?
回答by CB Bailey
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
回答by koppor
git --no-pager show -s --format='%an <%ae>' COMMIT
(Taken from quora.com)
(摘自quora.com)
--no-pager
supresses the pager-s
suppresses diff output%an
is the author name%ae
is the author email
--no-pager
抑制寻呼机-s
抑制差异输出%an
是作者名%ae
是作者邮箱