如何在给定SHA1的git中获取(仅)作者姓名或电子邮件?

Pat*_*ryk 19 git sha1 author commit

我想检查一下作者的电子邮件和姓名,以确认谁正在推送我的回购.

有没有办法让我在git中提出一个命令来显示提交者的名字/电子邮件,只提供提交的SHA1?

这就是我提出的,但它远非理想的解决方案(第一个解决方案是git hook,这就是为什么它使用2个SHA1 rev-list.第二个只是使用git show):

git rev-list -n 1 --pretty=short  ccd3970..6ddf170 | grep Author | cut -d ' ' -f2- | rev | cut -d ' ' -f2- | rev
git show 6ddf170 | grep Author | cut -d ' ' -f2- | rev | cut -d ' ' -f2- | rev 
Run Code Online (Sandbox Code Playgroud)

Iga*_* S. 28

您可以使用以下命令:

 git log --format='%ae' HASH^!
Run Code Online (Sandbox Code Playgroud)

它也适用git show.您需要包含-s以抑制差异.

git show -s --format='%ae' HASH
Run Code Online (Sandbox Code Playgroud)

  • 它与`git show`一起使用,但``git show`首先显示由`format`指定的提交信息,然后是diff.要抑制diff,添加`-s`选项(又名`--no-patch`). (2认同)
  • 你是对的.所以最好的方法就是简单:`git show -s --format ='%ae'HASH` (2认同)
  • 或同样简单的`git log -1 --format ='%ae'HASH`作为另一种选择:) (2认同)

小智 14

这将显示 - sha、提交者电子邮件、作者电子邮件

git log --pretty=format:"%h %ce %ae" HASH
Run Code Online (Sandbox Code Playgroud)


Cha*_*pat 13

git show <commit_id> | grep Author
Run Code Online (Sandbox Code Playgroud)

使用 git show + pipe + grep 工作!