您可以通过提交时间戳订购 git log 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36046222/
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
Can you order git log by commit timestamp?
提问by Tim Park
So I recently rebased a branch and merged it into master. When I do git log, I get a pretty, linear history of commits. But I want to see my commit history based on timestamp so I can easily compare when the commits on two branches were made in realtime.
所以我最近重新建立了一个分支并将其合并到 master 中。当我做 git log 时,我得到了一个漂亮的、线性的提交历史。但是我想根据时间戳查看我的提交历史记录,这样我就可以轻松地比较两个分支上的提交是何时进行的。
Is there a git log option that can order commits by timestamp instead of their normal commit history? I can't seem to find one. Thanks!
是否有一个 git log 选项可以按时间戳而不是正常的提交历史对提交进行排序?我似乎找不到一个。谢谢!
回答by Thibault D.
I was pretty sure it was possible using only git commands but I cannot find it now. --author-date-order
does notwork for me on rebased branch, as suggested in another answer.
我很确定只使用 git 命令是可能的,但我现在找不到它。--author-date-order
并没有对我来说有效在衍合分支,在另一个答案建议。
So one way to do that would be to use git log pretty=format: ...
to print the commit date in ISO format and let sort
or sort -r
fix the order.
因此,一种方法是使用git log pretty=format: ...
以 ISO 格式打印提交日期并让sort
或sort -r
修复订单。
For example:
例如:
git log --pretty=format:"%ad %h by %an, %s" --date=iso | sort -r | less
This will print the ISO date, the hash, the author and the message of the commit and sort it with the latest commits first.
这将打印 ISO 日期、哈希值、作者和提交消息,并首先使用最新提交对其进行排序。
You will find more format options at the PRETTY FORMATSsection of git log --help
if you need more information per commit.
如果您每次提交需要更多信息,您将在PRETTY FORMATS部分找到更多格式选项git log --help
。
回答by Diego Ruiz
git log --author-date-order
This command sorts by author's timestamp instead of commit's timestamp
此命令按作者的时间戳而不是提交的时间戳排序
--author-date-order
Show no parents before all of its children are shown, but otherwise show commits in the author timestamp order.
--作者日期顺序
在显示所有子项之前不显示父项,否则按作者时间戳顺序显示提交。