如何获取 git 日志以在一行上打印每个提交的完整哈希和简短统计信息?
How can I get git log to print the full hash and short stats of each commit on one line?
我想使用 git 命令行获得这种输出:
bcfd649de8850e3bfc9584eb12be8fe136ca6985 3 files changed, 8 insertions(+), 1 deletion(-)
我目前正在使用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(-)
有什么办法吗?
您可以定义自己的仅包含完整哈希的格式,并将 git log
的输出通过管道传输到 awk
(edit:或 sed
, ) in order to replace newlines by spaces where needed (see this):
git log --pretty=tformat:"%H" --shortstat | awk 'ORS=NR%3?" ":"\n"'
或
git log --pretty=tformat:"%H" --shortstat | sed 'N;N;y/\n/ /'
测试
$ 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(+)
$
对于任何登陆此处以回答“如何获取 git 记录一行完整提交哈希”的人,就像我所做的那样,git log
有一个标志,它打印 non-abbreviated 提交哈希。
叫做--no-abbrev-commit。文档内容如下:
Show the full 40-byte hexadecimal commit object name. This negates --abbrev-commit, either explicit or implied by other options such as "--oneline". It also overrides the log.abbrevCommit variable.
TL;DR: 这是 one-line 带有完整提交哈希的输出的命令:
git log --oneline --no-abbrev-commit
我想使用 git 命令行获得这种输出:
bcfd649de8850e3bfc9584eb12be8fe136ca6985 3 files changed, 8 insertions(+), 1 deletion(-)
我目前正在使用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(-)
有什么办法吗?
您可以定义自己的仅包含完整哈希的格式,并将 git log
的输出通过管道传输到 awk
(edit:或 sed
,
git log --pretty=tformat:"%H" --shortstat | awk 'ORS=NR%3?" ":"\n"'
或
git log --pretty=tformat:"%H" --shortstat | sed 'N;N;y/\n/ /'
测试
$ 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(+)
$
对于任何登陆此处以回答“如何获取 git 记录一行完整提交哈希”的人,就像我所做的那样,git log
有一个标志,它打印 non-abbreviated 提交哈希。
叫做--no-abbrev-commit。文档内容如下:
Show the full 40-byte hexadecimal commit object name. This negates --abbrev-commit, either explicit or implied by other options such as "--oneline". It also overrides the log.abbrevCommit variable.
TL;DR: 这是 one-line 带有完整提交哈希的输出的命令:
git log --oneline --no-abbrev-commit