简体   繁体   English

如何获取 git 日志以在一行上打印每个提交的完整 hash 和简短统计信息?

[英]How can I get git log to print the full hash and short stats of each commit on one line?

I would like to get this kind of output with git command line:我想用 git 命令行得到这种 output:

bcfd649de8850e3bfc9584eb12be8fe136ca6985 3 files changed, 8 insertions(+), 1 deletion(-)

I'm currently using git log --shortstat --reverse --pretty=oneline , but it's actually not a single line and the comment is useless to me:我目前正在使用git log --shortstat --reverse --pretty=oneline ,但它实际上不是一行,评论对我没用:

bcfd649de8850e3bfc9584eb12be8fe136ca6985 Added ActionController#cookies[] as a reader for @cookies that'll return the value of the cookie instead of 
3 files changed, 8 insertions(+), 1 deletions(-)

Is there any way to do it?有什么办法吗?

For anyone landing here for an answer to "how to get git log one line full commit hash", as I did, there is a flag for the git log which prints the non-abbreviated commit hash.对于任何登陆此处以回答“如何获取 git 日志一行完整提交哈希”的人,就像我一样, git log有一个标志,它打印非缩写的提交 hash。

It's called --no-abbrev-commit .它叫做--no-abbrev-commit Documentation reads as:文档内容如下:

Show the full 40-byte hexadecimal commit object name.显示完整的 40 字节十六进制提交 object 名称。 This negates --abbrev-commit, either explicit or implied by other options such as "--oneline".这否定了 --abbrev-commit,无论是显式的还是由其他选项(如“--oneline”)暗示的。 It also overrides the log.abbrevCommit variable.它还会覆盖 log.abbrevCommit 变量。

TL;DR: Here is the command for the one-line output with the full commit hash: TL;DR:这是单行 output 的命令,完整提交 hash:

git log --oneline --no-abbrev-commit

You can define your own format consisting only of the full hash, and pipe the output of git log to awk ( edit : or sed , as proposed by jthill in his comment ) in order to replace newlines by spaces where needed (see this ): 您可以定义自己的格式,仅包含完整哈希,并将git log的输出通过管道传输到awk编辑 :或sed由jthill在其注释中提出 ),以便在需要时用空格替换换行符(请参阅 ):

git log --pretty=tformat:"%H" --shortstat | awk 'ORS=NR%3?" ":"\n"'

or 要么

git log --pretty=tformat:"%H" --shortstat | sed 'N;N;y/\n/ /'

Test 测试

$ git log --pretty=tformat:"%H" --shortstat | awk 'ORS=NR%3?" ":"\n"'
4da27ca5dc8469f19b1524a5dd381aad76f96c69   4 files changed, 26 insertions(+)
60c1e011aadc1bdbf38dde989d0f0497925678d9   4 files changed, 34 insertions(+)
f0e6da70616337f135190dc7f68e22678a7af2ff   4 files changed, 34 insertions(+)
95ea8a002f66a249946a78deb362a2e697dfb80a   4 files changed, 44 insertions(+)
9854efba2301d520bc4fe1a102e102f299ae127d   1 file changed, 2 insertions(+), 2 deletions(-)
c8ee6b36a545c67b2443eea499bf046dd1e2233d   4 files changed, 29 insertions(+)
2d4374edd2d2820f05853b4add9fc5ddba1506ac   4 files changed, 42 insertions(+)
$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用短提交哈希+日期/时间进行git日志? - How do I git log with short commit hash + date/time? 如何在一行中获取带有简短统计信息的 Git 日志? - How to get Git log with short stat in one line? 如何在git中记录完整的提交消息? - How can I log full commit messages in git? 如何在没有作者、日期、提交消息和提交哈希的情况下获取 git 历史记录(日期范围)日志 - How can I get git history (date range) log to a file without author, date, commit message and commit hash 如何在我的PS脚本中获取Git commit哈希? - How can I get the Git commit hash in my PS script? 如何解析git log的响应? 我需要获取提交哈希和提交消息 - How to parse the response from git log ? I need to get the commit hash and the commit message 我怎样才能在 git 中获取文件的每次提交的代码行 - How can i get the line of code per commit for a file in git Git:如何在提交中列出更改的文件,包括每个文件 (blob) 的 SHA-1 哈希? - Git: How can I list the changed files in a commit, including the SHA-1 hash for each file (blob)? 我如何获得每次提交的代码行 - How I can get line of code for each commit 使用Github API从短哈希中获取git commit - Get git commit from short hash using Github API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM