如何制作仅在一行上显示日期和哈希值的git日志输出? [英] How to make git log output that just shows date and hash on one line?
本文介绍了如何制作仅在一行上显示日期和哈希值的git日志输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取Date并以这种格式提交一组github的结果:
I need to get the Date and commit results of a set of github in this format:
Date Commit
19 Mar 2015 b6959eafe0df6031485509c539e22eaf2780919c
1 Apr 2015 9a1f13339cc7d43930440c2350ea3060b72c8503
1 Apr 2015 1e76036421ca4d72c371182fc494af514911b099
我可以使用以下命令获取日期:
I am able to get the date with this command:
git log | grep Date: | awk '{print $4 " " $3 " " $6}'
和提交
git log | grep commit | awk '{print $2}'
我如何组合命令,以便在同一行中打印两个结果?
How can I combine the commands, so as to print both results in the same line?
以下是git日志的示例:
Here is an example of the git log:
commit 1e76036421ca4d72c371182fc494af514911b099
Author: xxxx
Date: Wed Apr 1 17:35:36 2015 +0200
First web app commit
First web app commit
commit 9a1f13339cc7d43930440c2350ea3060b72c8503
Author: xxxx
Date: Wed Apr 1 17:28:42 2015 +0200
change from app to website
commit b6959eafe0df6031485509c539e22eaf2780919c
Author: xxx
Date: Thu Mar 19 18:58:33 2015 +0100
First remote commit: hello world
scheleton of the project now available
commit a41d419de46a59e72dbc52e5f39c9d8a8a9af72a
Author: xxxx
Date: Thu Mar 19 17:31:16 2015 +0100
Initial commit
推荐答案
"git log"命令功能强大,可以自行处理.试一试:
The "git log" command is powerful enough to handle this on its own. Play around with variations on this:
git log --date=iso --pretty=format:"date={%ad}, commit={%H}"
这对我来说输出:
date={2014-12-12 14:14:23 -0800}, commit={75390af8bcd42c4dde6d841dc53f66a9ca91f460}
date={2014-12-09 18:53:32 -0800}, commit={8dcf9eb10611e6ac778e518cf37efb041c69f5b5}
date={2014-12-11 17:17:26 -0800}, commit={c3c1120b6dda6b317e1de5c7fe4eed7c8741ea1a}
要获得您指定的确切格式(尽管将日期格式设置得更合理),请尝试以下操作:
To achieve the exact format you specified (though with the date formatted a bit more reasonably), try this:
git log --date=short --pretty=format:"%ad %H"
哪个输出如下:
2015-08-18 1d0ca5a596f02958c4ba8ff269def3f235c64495
2015-08-18 d92fc3ebb62d2ca3e24322db2b669fdaebde7ea1
2015-08-18 6ba3970620e19699c2969b1eed5c479b07b8908a
这篇关于如何制作仅在一行上显示日期和哈希值的git日志输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文